Results 1 to 8 of 8

Thread: Some questions about custom drawing for QTabWidget/QTabBar

  1. #1
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Some questions about custom drawing for QTabWidget/QTabBar

    I have a QTabWidget with tabs which are created and removed dynamically depending upon what option user selects. Now, first thing i need to do is to achieve a look for the tabs as per the attached screenshot (tabs.jpg). So, as per the screenshot, the selected tab is blue and the other tabs are black. Also, the non-selected tabs have a different arrow-like shape.
    Here's how i think i can do it:

    1) Use stylesheet to set the background of the tabs. I am not sure if this will work properly and upto the desired level of look and feel. Also, in this case, the actual tabs will still be rectangular so it would be a problem.
    2) Subclass the QTabBar and draw the tabs myself in paint() method. For this i think i can do either of the following in paint() method:

    a) Set the background image for selected and de-selected tabs and use setMask to mask the widget i.e. tabs based on the image shape. So, this way i should get the non-rectangular shape for non-selected tabs.
    b) Draw the non-rectangular shape myself and set the background image or color.

    Please let me know your thoughts on this. Which approach is feasible or is any any other solution?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some questions about custom drawing for QTabWidget/QTabBar

    Use Graphics View for your tabs, as I already suggested in the other thread. And try to avoid spawning more than one thread on the same or very similar problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Some questions about custom drawing for QTabWidget/QTabBar

    Quote Originally Posted by wysota View Post
    Use Graphics View for your tabs, as I already suggested in the other thread. And try to avoid spawning more than one thread on the same or very similar problem.
    Thanks for the reply. Can you elaborate on how to use Graphics View for this? I already mentioned 2 approaches in my first post, so please suggest which one i should go for.

    And i was about to put this in the same thread but i thought it would get lost as the other thread had too many questions, sorry

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some questions about custom drawing for QTabWidget/QTabBar

    None of your approaches use graphics view. So the answer is "use graphics view". Each tab has to be an item in the scene and you need to implement the complete behaviour of the tab bar yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Some questions about custom drawing for QTabWidget/QTabBar

    thanks for the reply! let me study about graphics view more and i'll get back to this thread.

  6. #6
    Join Date
    Feb 2011
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Some questions about custom drawing for QTabWidget/QTabBar

    Hi all,
    I also have a trouble with QTabWidget and QTabBar. Please help me.
    I want to custome QTabWidget by creating a subclass of QTabWidget , creating subclass of QTabBar (such as: QTabWidgetSub, QTabBabSub ). After that, I use QTabWidgetSub::setTabBar in constructor of QTabWidgetSub.

    I want to change QTabBabSub height, but I can not. Do you have any idea?
    Thank you so much.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some questions about custom drawing for QTabWidget/QTabBar

    What have you tried so far? What exactly didn't work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2009
    Posts
    57
    Thanks
    7
    Thanked 5 Times in 4 Posts

    Default Re: Some questions about custom drawing for QTabWidget/QTabBar

    I am looking to do something similar -- i.e. changing the way tab bars are painted. The stylesheet settings are pretty limited and I would rather re-implement paint/paintEvent than "use graphicsscene" and "implement the complete behaviour of tab bar yourself" .. since this is really saying "write a custom widget and don't use QTabBar".

    Has anyone managed to get any success with painting the background and individual tabs of a QTabBar?

    What about the OP -- what did you do to resolve this?
    Last edited by liversedge; 5th June 2011 at 20:14. Reason: wrong bbcode tag usage

Similar Threads

  1. Drawing standard widgets using a custom paint engine
    By Waywocket in forum Qt Programming
    Replies: 26
    Last Post: 21st October 2010, 20:40
  2. Replies: 1
    Last Post: 3rd November 2009, 22:26
  3. Replies: 0
    Last Post: 10th October 2009, 05:44
  4. custom QColumnView, some questions
    By Mystical Groovy in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2009, 14:03
  5. Some questions about custom style
    By charlse in forum Qt Programming
    Replies: 0
    Last Post: 2nd April 2009, 09:54

Tags for this Thread

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.