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:
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!
-
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).
-
@Chris-Kawa This is still not fixed and the solution you added as a joke sounds more and more tempting to me...
-
See also https://bugreports.qt.io/browse/QTBUG-6905 - feel free to provide a fix for it, we're happy to review it :)
-
@Christian-Ehrlicher There are also QTBUG-50637, QTBUG-48994, QTBUG-30722, which are all the same issue reported over and over again. If you read the comments on the first one I tried to provide a fix, but it was bad (fixed one thing, broke another). Then Andy provided a patch that worked great as far as I can tell aaaand nothing happened. For whatever reason the patch never got through and the last comment on it is "I will try to get to it this week", which was a year ago ;)
-
@Chris-Kawa Maybe you can ping @AndyS again so we can take a look on it. I had no time for it to think about an own patch.