mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
picture effect tabbar add some iconstyle
This commit is contained in:
parent
beb9336465
commit
be51c6801a
@ -46,11 +46,11 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
g0 = ui->w99->addGraph(ui->w99->xAxis, ui->w99->yAxis);
|
||||
start = QTime::currentTime();
|
||||
|
||||
ui->tw0->setStyleSheet("QTabWidget#tw0 QTabBar::tab { width:90px; height:30px; }");
|
||||
QQtTabBar* tab = (QQtTabBar*)ui->tw0->localTabBar();
|
||||
tab->setIconStyle(QQtTabBar::IconStyle_Cover_And_RightText);
|
||||
tab->setTabPixmap(0, "./skin/default/bt_setting.png", "./skin/default/bt_setting_press.png");
|
||||
tab->setTabPixmap(1, "./skin/default/bt_user.png", "./skin/default/bt_user_press.png");
|
||||
ui->tw0->setStyleSheet("QTabWidget#tw0 QTabBar::tab { width:90px; height:30px; }");
|
||||
tab->setIconStyle(QQtTabBar::IconStyle_Left_And_RightText);
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,10 +11,12 @@ QQtTabBar::QQtTabBar(QWidget* parent) :
|
||||
QTabBar(parent)
|
||||
{
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
iconStyle = IconStyle_Cover_And_BottomText;
|
||||
iconStyle = IconStyle_Cover_And_RightText;
|
||||
textColor = QColor(0, 0, 0);
|
||||
backgroundColor = QColor(0, 0, 0);
|
||||
selectedTextColor = QColor(255, 255, 255);
|
||||
textFont = QApplication::font();
|
||||
setDrawBase(false);
|
||||
}
|
||||
|
||||
void QQtTabBar::setIconStyle(QQtTabBar::IconStyle iconStyle)
|
||||
@ -76,28 +78,54 @@ void QQtTabBar::setTabPixmap(int index, const QString& icon, const QString& icon
|
||||
iconList.insert(index, table);
|
||||
}
|
||||
|
||||
void QQtTabBar::setBackgroundColor(QColor backgroundColor)
|
||||
{
|
||||
if (this->backgroundColor != backgroundColor)
|
||||
{
|
||||
this->backgroundColor = backgroundColor;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void QQtTabBar::paintEvent(QPaintEvent* e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
QPainter p(this);
|
||||
drawBackground(&p);
|
||||
drawPicture(&p);
|
||||
drawText(&p);
|
||||
}
|
||||
|
||||
void QQtTabBar::drawBackground(QPainter* p)
|
||||
{
|
||||
bool b = drawBase();
|
||||
if (b)
|
||||
{
|
||||
for (int index = 0; index < count(); index++)
|
||||
{
|
||||
p->save();
|
||||
|
||||
p->setBrush(QBrush(backgroundColor));
|
||||
p->fillRect(tabRect(index), backgroundColor);
|
||||
p->restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QQtTabBar::drawPicture(QPainter* p)
|
||||
{
|
||||
for (int index = 0; index < count(); index++)
|
||||
{
|
||||
QRect iconRect = tabRect(index);
|
||||
if (iconStyle == IconStyle_Cover_And_BottomText)
|
||||
iconRect = tabRect(index);
|
||||
else if (iconStyle == IconStyle_Left_And_RightText)
|
||||
if (iconStyle == IconStyle_Left_And_RightText)
|
||||
iconRect = QRect(iconRect.left(), iconRect.top(),
|
||||
iconRect.height(), iconRect.height());
|
||||
|
||||
if (iconList.size() > index)
|
||||
{
|
||||
p->save();
|
||||
int sel = currentIndex() == index ? BTN_PRESS : BTN_NORMAL;
|
||||
//tabRect = rect()?
|
||||
p->drawPixmap(iconRect, QIcon(iconList[index][sel]).pixmap(iconRect.size(), QIcon::Normal, QIcon::On));
|
||||
/*
|
||||
* 失真不明显,使用以下方法
|
||||
@ -117,17 +145,19 @@ void QQtTabBar::drawText(QPainter* p)
|
||||
//-rect.height()/20 上移
|
||||
verticalTabs() ? tabTextRect.adjust(0, 0, 0, 0) : tabTextRect.adjust(0, 0, 0, 0);
|
||||
|
||||
if (iconStyle == IconStyle_Cover_And_BottomText)
|
||||
tabTextRect = tabRect(index);
|
||||
else if (iconStyle == IconStyle_Left_And_RightText)
|
||||
if (iconStyle == IconStyle_Left_And_RightText)
|
||||
tabTextRect = QRect(tabTextRect.left() + tabTextRect.height(), tabTextRect.top(),
|
||||
tabTextRect.width() - tabTextRect.height(), tabTextRect.height());
|
||||
|
||||
int flags = Qt::AlignCenter;
|
||||
if (iconStyle == IconStyle_Cover_And_BottomText)
|
||||
flags = verticalTabs() ? Qt::AlignHCenter | Qt::AlignBottom : Qt::AlignCenter;
|
||||
else if (iconStyle == IconStyle_Left_And_RightText)
|
||||
flags = Qt::AlignCenter;
|
||||
flags = Qt::AlignHCenter | Qt::AlignBottom;
|
||||
else if (iconStyle == IconStyle_Cover_And_TopText)
|
||||
flags = Qt::AlignHCenter | Qt::AlignTop;
|
||||
else if (iconStyle == IconStyle_Cover_And_LeftText)
|
||||
flags = Qt::AlignVCenter | Qt::AlignLeft;
|
||||
else if (iconStyle == IconStyle_Cover_And_RightText)
|
||||
flags = Qt::AlignVCenter | Qt::AlignRight;
|
||||
|
||||
//pline() << objectName() << rect;
|
||||
//if on board text is normal, this is right. otherwise the palette is right
|
||||
|
@ -17,7 +17,12 @@ public:
|
||||
|
||||
enum IconStyle
|
||||
{
|
||||
//picture style
|
||||
IconStyle_Cover_And_TopText,
|
||||
IconStyle_Cover_And_BottomText,
|
||||
IconStyle_Cover_And_LeftText,
|
||||
IconStyle_Cover_And_RightText,
|
||||
//color style
|
||||
IconStyle_Left_And_RightText,
|
||||
IconStyle_Max_Style
|
||||
};
|
||||
@ -37,8 +42,12 @@ public:
|
||||
void tabPixmap(int index, QImage& icon, QImage& iconSel);
|
||||
void setTabPixmap(int index, const QString& icon = QString(), const QString& iconSel = QString());
|
||||
|
||||
//effected by drawbase
|
||||
QColor getBackgroundColor() const { return backgroundColor; }
|
||||
void setBackgroundColor(QColor backgroundColor);
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent*);
|
||||
virtual void drawBackground(QPainter* p);
|
||||
virtual void drawPicture(QPainter* p);
|
||||
virtual void drawText(QPainter* p);
|
||||
|
||||
@ -53,6 +62,7 @@ private:
|
||||
QFont textFont;
|
||||
QColor textColor;
|
||||
QColor selectedTextColor;
|
||||
QColor backgroundColor;
|
||||
};
|
||||
|
||||
#endif // QQTTABBAR_H
|
||||
|
@ -9,7 +9,6 @@ QQtPictureEffectTabWidget::QQtPictureEffectTabWidget(QWidget* parent) : QQtTabWi
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void QQtPictureEffectTabWidget::setObjectName(const QString& name)
|
||||
{
|
||||
m_bar->setObjectName(QString("%1_bar").arg(name));
|
||||
|
Loading…
x
Reference in New Issue
Block a user