Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Automatic Clipping in QPaintEvent cuts away parts of the drawing result
Allgaeuer last edited by
I have created my own CGauge class, derived from QWidget, which displays a gauge. All the painting, including the needle etc., is done within the paintEvent of this class. Now I try place a QLabel behind the Gauge Widget, but within the area where my needle moves. The Label is used to display the analogue value of the gauge in a digital way and shall be displayed behind the needle.
The problem is that whenever the needle moves over the area of the Label, it gets painted torn-apart for a fraction of a second. That part of the needle which is be displayed over Label, is already further ahead than the rest of the needle. A short moment later, the needle gets painted correctly again. This looks very ugly when the needle should actually move smoothly over the Label.
I tracked the reason for the problem down to the Automatic clipping of Qt.
Whenever the Label gets repainted, Qt seems to detect that the Gauge is dirty and sends a QPaintEvent to it. But this event has a rectangle set, which identifies that region of the gauge, which is overdrawn by the Label. My Gauge class tries to draw the complete needle with a QPainter, but Qt internally seems to clip away all that is drawn outside of the area of the Label resp. not within the rectangle set on the QPaintEvent. This way, only the part of the needle which hovers the Label is drawn. Solely when my Gauge receives the QPaintEvent that "allows" it to draw over its complete area, it can draw the needle completely.
Do you have any ideas how to solve this problem or how to deactivate the Automatic clipping? How can I tell Qt that my Widget only makes sense to be drawn completely? Its not an option to only render the Widget when the QPaintEvent contains the full rectangle, since I cannot guarantee that this event ever arrives. Parts of my Widgets could reside outside of the visible area, which makes Qt never let me draw them.
Why does this Automatic clipping exist anyway? Isn't the post-processing of Paint Events to away parts of the drawing result unnecessary overhead?