Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1695648
  • 博文数量: 584
  • 博客积分: 13857
  • 博客等级: 上将
  • 技术积分: 11883
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-16 09:34

分类: WINDOWS

2011-11-27 00:28:57

  1. class TestTabBar : public QTabBar
  2. {
  3. public:
  4.     explicit TestTabBar(QWidget* parent=0) : QTabBar(parent)
  5.     {
  6.         setIconSize(QSize(80, 80));
  7.     }

  8. protected:
  9.     QSize tabSizeHint(int) const
  10.     {
  11.         return QSize(80, 80);
  12.     }
  13.     void paintEvent(QPaintEvent *)
  14.     {
  15.         QStylePainter p(this);
  16.         for (int index = 0; index < count(); index++)
  17.         {
  18.             QStyleOptionTabV3 tab;
  19.             initStyleOption(&tab, index);

  20.             QIcon tempIcon = tab.icon;
  21.             QString tempText = tab.text;
  22.             tab.icon = QIcon();
  23.             tab.text = QString();

  24.             p.drawControl(QStyle::CE_TabBarTab, tab);

  25.             QPainter painter;
  26.             painter.begin(this);
  27.             QRect tabrect = tabRect(index);
  28.             tabrect.adjust(0, 8, 0, -8);
  29.             painter.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText);
  30.             tempIcon.paint(&painter, 0, tabrect.top(), tab.iconSize.width(), tab.iconSize.height(), Qt::AlignTop | Qt::AlignHCenter);
  31.             painter.end();
  32.         }
  33.     }
  34. };

  35. class TestTabWidget : public QTabWidget
  36. {
  37. public:
  38.     explicit TestTabWidget(QWidget *parent = 0) : QTabWidget(parent)
  39.     {
  40.         setTabBar(new TestTabBar());
  41.     }
  42. };
阅读(2394) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~