Results 1 to 17 of 17

Thread: QTabWidget customization

  1. #1
    Join Date
    Apr 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QTabWidget customization

    hello everybody
    i have a problem with customization of the QTabWidget
    i want it to look like this:

    i attached a picture
    any idea
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    China
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTabWidget customization

    maybe use setTabPosition( TabPosition ) of QTabWidget. TabPosition = QTabWidget::West.
    I don't test, you can try.

  3. #3
    Join Date
    Apr 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTabWidget customization

    i'v tried the setTabPosition but i want to change the tab text direction to be vertical to the widget.
    thanx anyway

  4. #4
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTabWidget customization

    could u solved this problem.I need the same thing into bottom side.can u help me plz ? how to set tabposition?

  5. #5
    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

    Hey don't hijack 2 year old post! RTMF or at least read the thread you are writing in. The first answer tells you the solution!

  6. #6
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTabWidget customization

    This maybe help you:
    http://blog.csdn.net/notton/archive/...9/5996730.aspx


    --------------------------------------------------
    --------- Welcome www.thinkvd.com -------
    --------------------------------------------------

  7. #7
    Join Date
    Mar 2013
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTabWidget customization

    Quote Originally Posted by Lykurg View Post
    Hey don't hijack 2 year old post! RTMF or at least read the thread you are writing in. The first answer tells you the solution!
    Wait... seriously, "Guru", "Nokia Certified / Qt Developer"? At least you could follow your own comment "AT LEAST READ THE THREAD YOU ARE WRITING IN".

    Setting the TabWidget to WEST won't do what the poster asked for. And he already wrote it in the 3rd msg of this thread.

    I'm reading threads and it's full of little bastard saying "Read the f... manual".

    Maybe you should tell your mom "Hey bi@tch, you probably did't RTFM about how to raise kids!"

    By the way, it's RTFM, not RTMF... at least when you insult people, do it correctly!

  8. #8
    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

    Quote Originally Posted by cdebel2005 View Post
    Wait... seriously, "Guru", "Nokia Certified / Qt Developer"?
    Which came long after that post...

    Beside that, you must be really upset if your first post is to tell that (without helping the thread starter in any way). And as you obviously are stressed I was that time, and we both used a post to relieve that pressure. Not the right way, but as you showed with your post, we are not such different ;-)

    And I don't know what my mother have to do with it...

  9. #9
    Join Date
    Jul 2013
    Location
    Switzerland
    Posts
    4
    Thanked 4 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QTabWidget customization

    Quote Originally Posted by cdebel2005 View Post
    Wait... seriously, "Guru", "Nokia Certified / Qt Developer"?
    +1 to cdebel2005

    I've had this problem (and still do btw) and came across this thread.
    Reading answers like "RTFM (ahh... sorry RTMF)" is a waste of everybody's time.
    If you do not know the answer -- don't post. You are useless and of no help.

    And yes, I've used my first post to tell that... Because I am really upset with the "Guru's" like you.
    Last edited by ataraxic; 14th July 2013 at 11:56. Reason: reformatted to look better

  10. #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)

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

    CodeFreak (3rd August 2018)

  12. #11
    Join Date
    Jul 2013
    Location
    Switzerland
    Posts
    4
    Thanked 4 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QTabWidget customization

    Quote Originally Posted by Lykurg View Post
    Go ahead blaming me because of a typo.
    Exellent...
    That's what I was speaking about. Nice, neat, right to the point, no bullshit.
    Thanks for help!

    Sorry for the flames before. They were just because there are alot of >/dev/null posts around
    that are really annoying.
    Last edited by ataraxic; 16th July 2013 at 21:53.

  13. #12
    Join Date
    Jul 2013
    Location
    Switzerland
    Posts
    4
    Thanked 4 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QTabWidget customization

    There is another useful thread related to this question (west qtabwidget with horizontal text):

    http://www.qtforum.org/article/28672...b-positon.html

    Quote Originally Posted by Lykurg View Post
    Go ahead blaming me because of a typo
    Hello Lykurg,
    After trying your solution as is, I've got the following:

    west-tab.png

    Can you explain pls howto make horizontal text tabs and keep west qtab?

    Thank you!
    Last edited by ataraxic; 21st July 2013 at 10:53.

  14. #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 

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

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

  16. #14
    Join Date
    Jul 2013
    Location
    India
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget customization

    Hi Lykurg,

    Is this possible I use your solution to rotate tab bar text from vertical to horizontal. if possible means how?. I attached my output as image. see this,Screenshot from 2013-09-26 12:51:53.jpg

  17. #15
    Join Date
    Jul 2013
    Location
    Switzerland
    Posts
    4
    Thanked 4 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QTabWidget customization

    Here is a working example of the QTabWidget based on Lykurg CustomTabStyle class.
    Works like charm with QT5.0 && QT5.1

    tabdialog.pro:
    Qt Code:
    1. QT += widgets
    2.  
    3. SOURCES = main.cpp
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include <QtGui>
    2. #include <QWidget>
    3. #include <QDialog>
    4. #include <QApplication>
    5. #include <QtWidgets>
    6.  
    7. class CustomTabStyle : public QProxyStyle
    8. {
    9. public:
    10. QSize sizeFromContents(ContentsType type, const QStyleOption *option,
    11. const QSize &size, const QWidget *widget) const
    12. {
    13. QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
    14. if (type == QStyle::CT_TabBarTab)
    15. s.transpose();
    16. return s;
    17. }
    18.  
    19. void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
    20. {
    21. if (element == CE_TabBarTabLabel)
    22. {
    23. if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option))
    24. {
    25. QStyleOptionTab opt(*tab);
    26. opt.shape = QTabBar::RoundedNorth;
    27. QProxyStyle::drawControl(element, &opt, painter, widget);
    28. return;
    29. }
    30. }
    31. QProxyStyle::drawControl(element, option, painter, widget);
    32. }
    33. };
    34.  
    35. int main(int argc, char *argv[], char *envp[])
    36. {
    37. QApplication app(argc, argv);
    38.  
    39. QTabWidget *tabWidget = new QTabWidget;
    40.  
    41. tabWidget->setTabPosition(QTabWidget::West);
    42. tabWidget->tabBar()->setStyle(new CustomTabStyle);
    43.  
    44. tabWidget->addTab(new QWidget, "General");
    45. tabWidget->addTab(new QWidget, "Permissions");
    46. tabWidget->addTab(new QWidget, "Applications");
    47.  
    48. QVBoxLayout *mainLayout = new QVBoxLayout;
    49. mainLayout->addWidget(tabWidget);
    50.  
    51. tabWidget->show();
    52.  
    53. return app.exec();
    54. }
    To copy to clipboard, switch view to plain text mode 

    to compile (! M$):
    Qt Code:
    1. qmake -o Makefile tabdialog.pro
    2. make
    To copy to clipboard, switch view to plain text mode 

    output:
    horiz-tab-dialog.png

  18. The following 4 users say thank you to ataraxic for this useful post:

    Big_Stone88 (3rd April 2018), d_stranz (26th November 2017), Maximus2 (15th October 2013), Momergil (19th February 2014)

  19. #16
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QTabWidget customization

    Thanks for this. But I'm having some problems related to size of icon; resizing of tab width, height; setting the color of tab
    In tried like this, but I think that's not the proper way to change the size
    Qt Code:
    1. QSize sizeFromContents(ContentsType type, const QStyleOption *option,
    2. const QSize &size, const QWidget *widget) const
    3. {
    4. QSize s = QProxyStyle::sizeFromContents(type, option, QSize(40, 120), widget); // instead of size, I'm hardcoding the value with QSize(40, 120)
    5. if (type == QStyle::CT_TabBarTab)
    6. s.transpose();
    7. return s;
    8. }
    To copy to clipboard, switch view to plain text mode 
    1. I'm setting 64x64 pix icon, but still it's being displayed as a small icon. How do I set it to show original size of icon ?
    2. How to give custom width & height to the tab ?
    3. How to set the color of tab

    Kindly help. Thank you.
    Last edited by rawfool; 26th February 2014 at 12:07.

  20. #17
    Join Date
    Feb 2016
    Posts
    21
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTabWidget customization

    Hallo

    I know, this is an old Thread but i found it now ;-)

    On MAC (Sierra QT5.6) i can't see the Text.
    Any ideas?
    thx Chris

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.