I have reimplemented paintEvent for a number of my custom widgets
In a couple of places, I am having the problem that I need a repaint, even though the widget itself has not changed....this is because my paintEvent can depend upon settings which I have implemented elsewhere....(e.g. the user can choose one of a few radiobuttons which describe which colour they would like certain things to be, this radiobutton emits a signal which connects to a slot in the widget in question and this slot calls update()
I am definitely calling repaint()/update() (I have tried both) in the right places(AFIK)....but I think Qt must be optimizing and realizing that the widget itself has not in fact changed and thus does not call the paintEvent... it does not realise that the repaint depends on some third party info....and therefore does not update the colour until I change the value of the widget itself...
Is this expected behaviour? or have I missed a logical step in my signals and slots??
simplified code
layout->addWidget(radio1);
layout->addWidget(radio2);
layout->addWidget(radio3);
gb->setLayout(layout);
CustomWidget* cw = new CustomWidget();
connect(radio1, SIGNAL(clicked()), cw, SLOT(updateColour());
connect(radio2, SIGNAL(clicked()), cw, SLOT(updateColour());
connect(radio3, SIGNAL(clicked()), cw, SLOT(updateColour());
QGroupBox* gb = new QGroupBox("Group Box");
QVBoxLayout* layout = new QVBoxLayout();
QRadioButton *radio1 = new QRadioButton("Red");
QRadioButton *radio2 = new QRadioButton("Green");
QRadioButton *radio3 = new QRadioButton("Blue");
layout->addWidget(radio1);
layout->addWidget(radio2);
layout->addWidget(radio3);
gb->setLayout(layout);
CustomWidget* cw = new CustomWidget();
connect(radio1, SIGNAL(clicked()), cw, SLOT(updateColour());
connect(radio2, SIGNAL(clicked()), cw, SLOT(updateColour());
connect(radio3, SIGNAL(clicked()), cw, SLOT(updateColour());
To copy to clipboard, switch view to plain text mode
void CustomWidget::updateColour()
{
repaint(); //or update(); - I've tried both
}
void CustomWidget::updateColour()
{
repaint(); //or update(); - I've tried both
}
To copy to clipboard, switch view to plain text mode
{ //notice that no members in the widget changed at all
if(blue was clicked)
change the palette to blue and call BaseClass::repaint();
else if(red was clicked)
as abve....usw....
}
void CustomWidget::paintEvent(QPaintEvent* event)
{ //notice that no members in the widget changed at all
if(blue was clicked)
change the palette to blue and call BaseClass::repaint();
else if(red was clicked)
as abve....usw....
}
To copy to clipboard, switch view to plain text mode
Bookmarks