[Interest] Overwriting Painting Of Widgets

Jonathan Purol contact at folling.de
Sun Jun 14 18:45:34 CEST 2020


I attempted to have a vertical tabbar on the left, similar to what you'd
have in QtCreator or VSCode. However, Qt automatically rotates the label
on the left, which includes the icon. I attempted to go around this by
subclassing QTabBar (and subsequently QTabWidget to use my custom
TabBar) overwriting `paintEvent` and then counter-rotating the painter
before continuing to paint the label.

This worked well, but an issue was brought forth when I tried to reorder
the tabs. It's quite fuzzy to describe, but it's probably sufficed to
say: The dragged tab wasn't drawn correctly. However, there was also no
way to draw that dragged tab myself, since knowing which tab is dragged
is part of QTabBarPrivate and thus not accessible.

I know I could go around this by writing a proxy style, but I refuse to
believe that there is no way to customize the painting short of the
proxy style or writing my own TabBar implementation from scratch. It
would go for quite a few widgets actually. ItemViews at least give you
ItemDelegates to that help(although those still lack the ability to
embed widgets into non-edition drawing).

Yes I am aware that I could just fake the tabbar with a
QVBoxLayout/QListView and a StackedLayout, but that's not the point of
my question, it's merely the reason it came to my mind.
I'm really just curious how slight changes to the drawing behaviour
could be implemented in Qt. I can think of a myriad of usecases here:
1. A QDoubleSpinbox with the de/increment buttons on the other side
2. A QLineEdit with a non-blinking cursor
3. A QTabBar that doesn't rotate its icons
4. A QPushButton with a dripple effect
...
Just small changes, that seem to require completely writing your own
widget, instead of just altering the drawing process.

Sincerely,
Jonathan Purol


More information about the Interest mailing list