CSS padding inside QTabWidget tabs hiding text

  • Hi everyone

    I'm making an application which uses a QTabWidget which I would like to customise with CSS. The text in each tab can be quite long (an absolute file path) and I would like it to be truncated so that the tabs stay at a reasonable size. To achieve this I'm using setElideMode, which works fine for CSS styled tabs as long as there is no padding.

    Here is an image so you can see what's going on:
    alt text

    The first two tabbars are without padding, and in the second one the tabbar is shorter and the text is elided correctly. In the secont pair 5px padding is added but the text elide is still caculated as if there were no padding. This is causing the text that overlaps with the padding to be hidden.

    Is there any way to make the text display properly between the padding at either side? I know I can override paintEvent for my tabbar altogether but I was hoping there is an easier solution. Any suggestions are welcome, thanks in advance!

  • Moderators

    That's definitely a bug. There seems to be a bug report about it QTBUG-15203, but it has been closed due to Qt4 EOL. Since it's still valid please report it for Qt5.

    As for a workaround I'm afraid you will need to paint the tabs yourself. If you don't wan't to subclass and override paintEvent you can install an event filter and handle the painting there. Other that that I can't think of any other solution, apart maybe from adding some spaces to the front of the strings :P (just kidding, don't do it).

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.