资源简介
QT下实现类似QQ聊天窗口tab控件 ,包含自定义控件CCustomTabWidget 及使用范例程序
代码片段和文件信息
#include “ccustomtabwidget.h“
#include
#include
#include
#include
#include
#include
#include yleOption>
#include
CCustomTabButton::CCustomTabButton(QWidget *parent):
QPushButton(parent)
{
this->setCheckable(true);
m_btnClose = new QPushButton(this);
m_btnClose->setobjectName(QString::fromUtf8(“CCustomTabCloseButton“));
m_btnClose->setVisible(false);
m_btnClose->setGeometry(QRect(this->width()-1601616));
connect(m_btnClose SIGNAL(clicked()) this SLOT(on_btnClose_clicked()));
}
CCustomTabButton::~CCustomTabButton()
{
delete m_btnClose;
}
void CCustomTabButton::resizeEvent(QResizeEvent * event)
{
m_btnClose->setGeometry(QRect(this->width()-1601616));
}
void CCustomTabButton::mousePressEvent(QMouseEvent * event)
{
emit clicked(m_nIndex);
}
void CCustomTabButton::enterEvent ( QEvent * event )
{
QPushButton::enterEvent(event);
m_btnClose->setVisible(true);
}
void CCustomTabButton::leaveEvent ( QEvent * event )
{
QPushButton::leaveEvent(event);
m_btnClose->setVisible(false);
}
void CCustomTabButton::on_btnClose_clicked()
{
emit closeClicked(m_nIndex);
}
void CCustomTabButton::setText(QString text)
{
QPushButton::setText(text);
this->setToolTip(text);
}
/***
CCustomTabWidget
**/
CCustomTabWidget::CCustomTabWidget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout *vlMain = new QVBoxLayout();
vlMain->setSpacing(0);
vlMain->setMargin(0);
this->setLayout(vlMain);
m_lblTabbar = new QLabel();
m_lblTabbar->setobjectName(QString::fromUtf8(“CCustomTabBar“));
m_hlTabbar = new QHBoxLayout();
m_hlTabbar->setSpacing(0);
m_hlTabbar->setMargin(0);
m_hlTabbar->setContentsMargins(5050);
m_hlTabbar->addStretch();
m_lblTabbar->setLayout(m_hlTabbar);
vlMain->addWidget(m_lblTabbar);
m_stackWidget = new QStackedLayout();
vlMain->addLayout(m_stackWidget);
}
CCustomTabWidget::~CCustomTabWidget()
{
for (int i = 0; i < m_listTabButton.size(); i++)
{
delete m_listTabButton.at(i);
}
m_listTabButton.clear();
for (int i = 0; i < m_stackWidget->count(); i++)
{
delete m_stackWidget->widget(i);
}
delete m_lblTabbar;
delete m_stackWidget;
}
void CCustomTabWidget::paintEvent(QPaintEvent *)
{
QstyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(Qstyle::PE_Widget &opt &p this);
}
void CCustomTabWidget::on_tabbar_closeClicked(int nIndex)
{
if (nIndex < 0 || nIndex >= m_listTabButton.size())
{
qDebug()<<“CCustomTabWidget::on_tabbar_closeClicked error!!!“< return;
}
this->RemoveTab(nIndex);
}
void CCustomTabWidget::on_tabbar_clicked(int nIndex)
{
if (nIndex < 0 ||
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6300 2013-10-12 09:26 TestTabbar\ccustomtabwidget.cpp
文件 1692 2013-10-12 09:23 TestTabbar\ccustomtabwidget.h
文件 1339 2013-10-10 09:29 TestTabbar\dialog.cpp
文件 480 2013-10-08 14:22 TestTabbar\dialog.h
文件 2098 2013-10-10 09:28 TestTabbar\dialog.ui
文件 1122 2013-10-12 09:07 TestTabbar\main.cpp
文件 3725 2013-10-09 10:57 TestTabbar\skin\tab_bg.png
文件 2997 2013-10-09 10:28 TestTabbar\skin\tab_btn_bg_checked.png
文件 3076 2013-10-09 15:54 TestTabbar\skin\tab_btn_bg_hover.png
文件 169 2013-10-09 15:48 TestTabbar\skin\tab_btn_bg_normal.png
文件 368 2013-10-09 11:02 TestTabbar\skin\tab_btn_close_hover.png
文件 3169 2013-09-18 17:25 TestTabbar\skin\tab_btn_close_normal.png
文件 343 2013-10-09 15:48 TestTabbar\testbar.qrc
文件 409 2013-10-08 17:49 TestTabbar\TestTabbar.pro
文件 23502 2013-10-12 09:07 TestTabbar\TestTabbar.pro.user
目录 0 2013-10-09 15:54 TestTabbar\skin
目录 0 2013-10-08 17:50 TestTabbar
----------- --------- ---------- ----- ----
50789 17
评论
共有 条评论