Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel update()
Qt 6.11 is out! See what's new in the release blog

QLabel update()

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aidaqt
    wrote on last edited by
    #1

    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: QLabel

    That 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...

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      What happens if you envelop the call with signal blocking? Like this:
      @
      qlabel->blockSignals(true);
      qlabel->update();
      qlabel->blockSignals(false);
      @

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aidaqt
        wrote on last edited by
        #3

        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@

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.
          @

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aidaqt
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [quote author="aidaqt" date="1390824187"]Is this normal?[/quote]

              I don't know, I have not investigated paint event handling in depth before.

              (Z(:^

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved