PDA

View Full Version : Some questions about custom drawing for QTabWidget/QTabBar



montylee
20th November 2009, 07:35
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?

wysota
20th November 2009, 09:36
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.

montylee
20th November 2009, 09:55
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 :)

wysota
20th November 2009, 12:26
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.

montylee
22nd November 2009, 15:50
thanks for the reply! let me study about graphics view more and i'll get back to this thread.

posixprogrammer
24th April 2011, 14:27
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.

wysota
25th April 2011, 11:18
What have you tried so far? What exactly didn't work?

liversedge
5th June 2011, 20:12
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?