drawControl not being called for custom styled elements
-
So, when using a custom style for my QScrollBar for control elements, the drawControl function does not seem to get called ever. Is there any specific condition when this function is called?
-
CC_ScrollBar is, as you can see a complex control so if you want to handle CC_ScrollBar you should override drawComplexControl()
-
@Christian-Ehrlicher I tried overriding that function as well, but it does not get called.
Also if I wanted to draw separate elements, like the add page and sub page of the scrollbar, how would it be possible with the drawControl/drawComplexControl?
-
Override those functions and reimplement what you want.
You should also make sure that you really use your style. -
@Christian-Ehrlicher Tried doing that, neither the drawControl or drawComplexControl get called. What might I be doing wrong?
-
@ateek-ujjawal said in drawControl not being called for custom styled elements:
What might I be doing wrong?
You are not using your style as I already told you.
-
@Christian-Ehrlicher Is this not the correct way of doing it?
_ui.slicingScrollBar->setStyle(new CustomStyle);
The slicingScrollBar is a QScrollBar. The CustomStyle is defined as follows:
class CustomStyle : public QProxyStyle { Q_OBJECT public: CustomStyle(); ~CustomStyle() {}; void drawPrimitive(PrimitiveElement pe, const QStyleOption* opt, QPainter* p, const QWidget* widget) const override; void drawControl(ControlElement ce, const QStyleOption* opt, QPainter* p, const QWidget* w = nullptr) const override; void drawComplexControl(ComplexControl cc, const QStyleOptionComplex* opt, QPainter* p, const QWidget* widget = nullptr) const override; };
-
Hi,
What if you set it on QApplication ?
-
Start from the example in https://doc.qt.io/qt-6/qproxystyle.html#details and see what happens.
-
@Christian-Ehrlicher Uh, I don't see how overriding the style hint would help. I searched the QStyle enum for options I needed and I came up with nothing useful.
-
You should start with this example to see if it works and then add your function to find out what is going wrong...