Results 1 to 14 of 14

Thread: QTabBar with optional button to the right of every tab

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QTabBar with optional button to the right of every tab

    Hi, I want to have an extra button on a QTabBar, like the closeButton in Firefox. My current solution is subclassing from QTabWidget and doing the drawing myself. It works but I'm losing the boons of CSS-Styling . This way I need to write a new class every time I want to implement a different look. Is there a way to achieve the same effect without losing the Styleability of the widget or is it possible to access the defined stylesheet values without doing all the parsing logic so I can try to take them into consideration when painting the tabbar? ... like getter functions for the properties and also the properties for the subcontrols?

    Thanx in advance
    Last edited by momesana; 6th October 2007 at 21:46.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTabBar with optional button to the right of every tab

    I'm not 100% sure but I think some of those Qt 4 dedicated IDEs out there have such tabs. Of course, it has also been suggested to Trolltech: http://trolltech.com/developer/task-...ntry&id=137891
    J-P Nurmi

  3. #3
    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: QTabBar with optional button to the right of every tab

    To be honest QTabBar/QTabWidget API sucks when it comes to modifying it. If you take a look at the sources, it depends heavily on P-IMPL and QStylePainter. In my opinion these classes need to be redesigned. It might be hard because of a need to maintain backward compatibility, but currently QTabBar is surely one of the hardest widgets to extend, so something should be done about it. The least they could do is to introduce the "icon" property (or taking the icon from the widget associated with the tab) and "iconClicked()" signal. That should be doable without introducing any virtual methods.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTabBar with optional button to the right of every tab

    Thanks for replying. I guess then I have to use my own class and sacrifice Stylability until the trolls come up with a better solution (I hope they do, even though it doesn't seem like they care too much from looking at the bug entry).

    Thanx.

  5. #5
    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: QTabBar with optional button to the right of every tab

    It could be because it would be hard to implement on MacOS for instance... MacOS tab bars don't have space for icons and it'd look silly if you just sticked an icon there.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTabBar with optional button to the right of every tab

    Quote Originally Posted by wysota View Post
    It could be because it would be hard to implement on MacOS for instance... MacOS tab bars don't have space for icons and it'd look silly if you just sticked an icon there.
    I've never worked with MacOS so I can't tell but generally having such an optional icon is a good thing, at least when it really is optional. It really improves usability when there are many open tabs like in a browser.

  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: QTabBar with optional button to the right of every tab

    I know it's a good thing. I've been trying to implement that d**n thing on QTabBar for days... Each time I ended up concluding that currently one needs to implement almost everything from scratch.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTabBar with optional button to the right of every tab

    Quote Originally Posted by wysota View Post
    Each time I ended up concluding that currently one needs to implement almost everything from scratch.
    Same result here...
    J-P Nurmi

  9. #9
    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: QTabBar with optional button to the right of every tab

    Quote Originally Posted by jpn View Post
    Same result here...
    Maybe we should cooperate? It would only be half a scratch each

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTabBar with optional button to the right of every tab

    A joint venture between libQxt and wwidgets :-D and I'll be the consumer of the result :-D.

  11. #11
    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: QTabBar with optional button to the right of every tab

    Honestly I don't think we'd be able to do anything really useful and platform independent without Trolltech changing the API. The widget simply relies too much on p-impl and style code. Without decoupling those there is not much we can do - there is no API to retrieve the icon rect of each tab for instance.

  12. #12
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTabBar with optional button to the right of every tab

    Quote Originally Posted by wysota View Post
    The widget simply relies too much on p-impl and style code. Without decoupling those there is not much we can do - there is no API to retrieve the icon rect of each tab for instance.
    Well, the Icon (the closebutton) is to always be placed on the right. That's where almost all the implementations of tabbars place the icon. And the icon is always horizontally centered. I have never come across anything else in real software. So the only thing to add is to add some space between the right tab border and the icon. The spacing should somehow be deduced from the Style or the StyleSheets.

    In my implementation I've introduced a setSpacing member function that defines how much spacing there is between the three elements (left default icon, text and the right icon) and the surrounding tab borders. So I have three functions that each take a QRectF (the rect that the programmer wants to paint to calculated from what it has really been allocated by tabRect()), and return the area the left icon, the text and the right icon are to be located based on iconSize(), spacing and fontMetrics. It also works when I catch a mousePressEvent and want to find out if the area clicked coincides with the location of the close-icon.

    Of course this is not the optimal solution but I guess it is the only quick and dirty way to do it and a trolltech sponsored QTabWidget is (unfortunately) not on the horizon. So why not implement it this way to give the desperate a choice even though it is not optimal? Isn't it possible to get something that works and also respects the Style and additional StyleSheets?

  13. #13
    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: QTabBar with optional button to the right of every tab

    Quote Originally Posted by momesana View Post
    Well, the Icon (the closebutton) is to always be placed on the right. That's where almost all the implementations of tabbars place the icon. And the icon is always horizontally centered. I have never come across anything else in real software.
    The problem is QTabBar already has support for icons and they are placed on the left of the tab. Furthermore a tab can have an icon, but it doesn't have to. A whole tab, a part of it or none of it can be shown in the bar, etc. There are many things to think about and no support for that in public API. And using different styles and stylesheets complicates the situation even more. And what about making space for the icon if the tab text is so wide it occupies the whole width of the tab? Again, no support for that in the API. You'd have to reimplement half of the paint event to make the tab not draw its text and then draw it manually in a correct rectangle.

    In my implementation I've introduced a setSpacing member function that defines how much spacing there is between the three elements (left default icon, text and the right icon) and the surrounding tab borders. So I have three functions that each take a QRectF (the rect that the programmer wants to paint to calculated from what it has really been allocated by tabRect()), and return the area the left icon, the text and the right icon are to be located based on iconSize(), spacing and fontMetrics. It also works when I catch a mousePressEvent and want to find out if the area clicked coincides with the location of the close-icon.
    I think you simplified it too much. Have you tried it with different styles, tab positions and shapes, icon sizes? I think your solution is fine for some cases, but for others it will fail badly (for instance on Mac where tabs are centered and their contents centered within tabs). Here, look:


    Or the one below (click for a large version), see how complex it is (for instance the partially hidden tab on the right):
    arc1.png

    Isn't it possible to get something that works and also respects the Style and additional StyleSheets?
    In my opinion not without reimplementing half of the class. Believe me, I spent hours thinking about it and came to no conclusions of doing it the right way.

  14. #14
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Wink Re: QTabBar with optional button to the right of every tab

    Quote Originally Posted by wysota View Post
    The problem is QTabBar already has support for icons and they are placed on the left of the tab. Furthermore a tab can have an icon, but it doesn't have to. A whole tab, a part of it or none of it can be shown in the bar, etc.
    I paint the widget in the rect tabRect() returns to me. Then the TabBar takes responsibility of displaying the Tabs, sometimes truncating the stuff.

    There are many things to think about and no support for that in public API. And using different styles and stylesheets complicates the situation even more.
    Yes, Styles and stylesheets are the obstacles that I cannot overcome

    And what about making space for the icon if the tab text is so wide it occupies the whole width of the tab?
    I do it like that. First I make sure that sizeHint returns a value larger then the number of icons + the size of ... so that the minimal size can host the icons that are enabled and the ellipses. Then I pass the text to be displayed to fontMetrics::elipsedText() with the rect that the selfwritten textRect member function has calculated for the text.

    Again, no support for that in the API. You'd have to reimplement half of the paint event to make the tab not draw its text and then draw it manually in a correct rectangle.

    I think you simplified it too much.
    definitely :-). Otherwise I wouldn't have been able to implement it in the first place. Its a brute force implementation that is not reusable at all. I am not even sure it works on windows (gotta try that tomorrow).

    Have you tried it with different styles, tab positions and shapes, icon sizes? I think your solution is fine for some cases, but for others it will fail badly (for instance on Mac where tabs are centered and their contents centered within tabs).
    I have tried it with different styles but not with different tab positions or shapes. since I've implemented paintEvent() myself and do all the drawing it always looks the same which is the problem in the first place. :-(
    Still, a tabWidget with an extra button would really be a nice thing to have, even if the implementaion is limited or not very cleanly implemented. My implementation does not respect styles or stylesheets so it is not reusable. But if there was something which would at least halfway respect such Styles and Stylesheets that would be enough. If trolltech doesn't do it, the next authorities that are obliged (or capable) to implement it are the libQxt team (with jpn as their ambassador to this forum) and the wwwidgets team (which is you wysota). :-D.

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.