QGraphicsColorizeEffect resizes widgets
-
Hi all.
I have a vertical navigation menu with six navigation buttons. The height of the navigation menu is exactly six times the height of one button. Both buttons and menu is set to a fixed size.
The menu looks like this.
The top button has a lighter color. Unfortunately the others are a little diffucult to see. If I put a QGraphicsColorizeEffect on the menu. Then it looks like this.
The Graphics effect is there, but only three buttons remain.
I actually set the effect before the first picture, and then i set the strength to zero (which I assume looks the same as no effect?). In the second picture I set the strength to higher than zero.
If I reset the strength to zero, then the effect disappears - as expected - but still only three buttons remain.
The code of the base class looks like this:#include "TargetFocus.h" #include "UI.h" #include <QGraphicsColorizeEffect> #include <QDebug> #define ACTIVATE 0.2 #define DEACTIVATE 0 #define ACTIVE_COLOR "blue" //0x272727 TargetFocus::TargetFocus(QWidget *parent, UI& ui, MainFocus::Position position) : QWidget{parent}, effect(new QGraphicsColorizeEffect), position(position) { effect->setColor(ACTIVE_COLOR); effect->setStrength(DEACTIVATE); setGraphicsEffect(effect); connect(ui.mainFocus, &MainFocus::choose, this, &TargetFocus::choose); } void TargetFocus::choose(MainFocus::Position target) { if (position == target) qDebug() << position; if (position == target) effect->setStrength(ACTIVATE); else effect->setStrength(DEACTIVATE); }
When I run the program, then I get a lot of.
QPainter::begin: A paint device can only be painted by one painter at a time. QPainter::translate: Painter not active
As application output. These outputs seems to be related to the function call setGraphicsEffect(effect). If I remove that line, then of course nothing happens, but I also do not get these QPainter messages.
What do you think I should do?
-
@Jakob-Clausen Anyone?
-
Hi,
Do you mean you have that effect once you start changing the effect strength ?
-
Not at first.
This is the sequence of events:- call constructor
- set stength to zero
- setEffect on widget
- change strength to larger than zero
at the last point problems happen
-
What does the error messages
QPainter::begin: A paint device can only be painted by one painter at a time. QPainter::translate: Painter not active
mean?
-
@Jakob-Clausen Do you have more than one painter on same device?
-
@jsulm Good question. I was wondering the same thing. It looks like a painter is added, when I set the graphics effect. Is this true?
The widget upon which the effect is set, is also added to a qstackedwidget. Could that cause the ... no more than one painter ... thing? If I add the effect to the qstackedwidget aka the parent, then this error also is no more.
But it still does not look right.
Do I need to repaint the widget? -
Something else is strange. Maybe a clue?
The navigation looks like it only has three buttons left. But all six of them are there. I can push them all, and the QWidgetStack changes accordingly. So the buttons are where they should be. But it looks like they are not.
And if I remove the effect, then I can make it all look well by calling repaint(). -
Are there any limitations on the QGraphicsColorizeEffect?
Should it not be possible to just set it on any old widget? -
@Jakob-Clausen Do you paint manually on that widget (in paintEvent)?
-
No. I add subwidgets to a layout and thats it.
-
I think I have found a way through it all. I can create a new widget of the same size and shape, and instead of a QGraphicsColorizeEffect I can use a QOpacityEffect and the move it to cover the navigationbar. But then the navigation wont accept touch events. Any around that?