Results 1 to 17 of 17

Thread: QTabWidget customization

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTabWidget customization

    You only have to change a row and add one:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class CustomTabStyle : public QProxyStyle
    4. {
    5. public:
    6. QSize sizeFromContents(ContentsType type, const QStyleOption *option,
    7. const QSize &size, const QWidget *widget) const
    8. {
    9. QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
    10. if (type == QStyle::CT_TabBarTab)
    11. s.transpose();
    12. return s;
    13. }
    14.  
    15. void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
    16. {
    17. if (element == CE_TabBarTabLabel)
    18. {
    19. if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option))
    20. {
    21. QStyleOptionTab opt(*tab);
    22. opt.shape = QTabBar::RoundedNorth;
    23. QProxyStyle::drawControl(element, &opt, painter, widget);
    24. return;
    25. }
    26. }
    27. QProxyStyle::drawControl(element, option, painter, widget);
    28. }
    29. };
    30.  
    31. int main(int argc, char *argv[])
    32. {
    33. QApplication a(argc, argv);
    34.  
    35. QTabBar tb;
    36. tb.setStyle(new CustomTabStyle);
    37. tb.setShape(QTabBar::RoundedWest);
    38. tb.addTab("Tab 1");
    39. tb.addTab("Tab 2");
    40. tb.show();
    41.  
    42. return a.exec();
    43. }
    To copy to clipboard, switch view to plain text mode 

  2. The following 2 users say thank you to Lykurg for this useful post:

    Big_Stone88 (3rd April 2018), Momergil (19th February 2014)

Similar Threads

  1. QTabWidget remove a page at the page's request
    By thomaspu in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2007, 20:45
  2. add a label in a QTabWidget
    By sabeesh in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2007, 07:36
  3. Adding QGroupBox to QTabWidget
    By mclark in forum Newbie
    Replies: 2
    Last Post: 17th January 2007, 16:27
  4. QTabWidget Placement and Display
    By mclark in forum Newbie
    Replies: 1
    Last Post: 16th January 2007, 20:34
  5. Corner widget in QTabWidget doesn't show up
    By ePharaoh in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2006, 17:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.