QLabel update()
-
Hi,
If I call a qlabel->update(), which QWidget should be updated? When I update a QLabel inside my QStatusBar and inside my QMainWindow I'm reciving event type 12 (Paint) in:
12: MainWindow
12: Tree
12: MessageWindow
12: QWidget (central widget)
12: QMenuBar
12: QToolBar
12: QStatusBar
12: QLabelThat is: all QWidgets child of my QMainWindow. Is this the normal behaviour? I want to update four times in a second my QLabel and this is slowing down my app...
-
What happens if you envelop the call with signal blocking? Like this:
@
qlabel->blockSignals(true);
qlabel->update();
qlabel->blockSignals(false);
@ -
Still same behaviour, 8 Paint event 4 times on each second
@ std::cerr << "update" << std::endl;
progressLabel->blockSignals(true);
progressLabel->update();
progressLabel->blockSignals(false);QCoreApplication::processEvents();
std::cerr << "done" << std::endl;@
and also printing in the eventFilter the type of the events:
@std::cerr << event->type()<<": " << obj->metaObject()->className() << std::endl;@
@update
12: MainWindow
12: Tree
12: MessageWindow
12: QWidget
12: QMenuBar
12: QToolBar
12: QStatusBar
12: QLabel
done@ -
OK, now a more hard-core solution (well, alright, we will call it a "solution" only if it works :P). Subclass QLabel, and reimplement paintEvent() and accept the event there:
@
event->setAccepted(true);
@Or, every time you run update, make sure to disable updates for all those other classes in your hierarchy (this will be tedious and error-prone) with:
@
mainWindow->setUpdatesEnabled(false);
// etc.
@ -
Inserting and using this class:
@class MYQLabel : public QLabel{
void paintEvent(QPaintEvent * event)
{
QStyleOption opt;
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
event->setAccepted(true);
std::cerr << "Accepted" << std::endl;
}};@
Now the output is the same:
@update
12: MainWindow
12: Tree
12: MessageWindow
12: QWidget
12: QMenuBar
12: QToolBar
12: QStatusBar
Accepted
12: QLabel
done@Is this normal?
-
[quote author="aidaqt" date="1390824187"]Is this normal?[/quote]
I don't know, I have not investigated paint event handling in depth before.