Results 1 to 17 of 17

Thread: QTabWidget customization

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    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

    Go ahead blaming me because of a typo. You also seem to not have understand the relation between tags like "Guru" and time of posting. Beside, I didn't gave me the title "Guru". It is just related on how many post you do here. Even if they are crap. So please do not blame me for things I am not responsible for. But anyway go on, dish the dirt, I do not care.

    Or you can start spending the time solving your problem. As I am not very willing to help you after such comment (problem is the language not necessarily the content), but for the sake of peace I give a starting point. You just have to change it for your needs:

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

    To protect me against an other shit storm about how a Guru can write such a code: It is not the most elegant solution - I know -, but it is easy, quick and working.

    EDIT: For a good starting point of reading: http://qt-project.org/doc/qt-4.8/style-reference.html (section Tabs)

  2. The following user says thank you to Lykurg for this useful post:

    CodeFreak (3rd August 2018)

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.