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. QT 5.3 - need to force an "immediate" redraw of a widget
Forum Updated to NodeBB v4.3 + New Features

QT 5.3 - need to force an "immediate" redraw of a widget

Scheduled Pinned Locked Moved General and Desktop
qlabelredraw immediat
7 Posts 3 Posters 30.2k Views 3 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.
  • J Offline
    J Offline
    Jeff Andle
    wrote on last edited by
    #1

    I have a section of code that processes a data packet. I want to flash a green "led" in the status bar to show that the data was received. The code below does not flash it. This makes sense since the UI never gets the processor (Arm9) to redraw the widget. Even a sleep there does not yield to the redraw. By the time it redraws I have reset the style sheet.

    void process ()
    {
    //QLabel leRxData;
    ...
    ui->leRxData->setStyleSheet(...); // make the label be a green indicator
    QThread::msleep (20);
    ...
    // process the data
    ...
    ui->leRxData->setStyleSheet(...); // make the label be an unlit indicator
    retuen;
    }

    J 1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      HI and welcome to devnet,

      I'm not sure to fully understand your problem but you can can force the redraw calling QWidget::repaint()

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      J 2 Replies Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Are you trying to do something like QLed ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        J 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Are you trying to do something like QLed ?

          J Offline
          J Offline
          Jeff Andle
          wrote on last edited by
          #4

          @SGaist more of a welcome back... I could not access my JCAndle profile so I reset... you were helping me quite a bit earlier on. I'll look at QLed and may be I am just reinventing it.

          1 Reply Last reply
          0
          • M mcosta

            HI and welcome to devnet,

            I'm not sure to fully understand your problem but you can can force the redraw calling QWidget::repaint()

            J Offline
            J Offline
            Jeff Andle
            wrote on last edited by
            #5

            @mcosta I'll try that. I'd post a screen shot if I knew how to embed it here, but I want to light up a widget on my status bar when I enter a section of code and darken it when I leave. I was using setStyleSheet() to modify the background color of a QLabel with text identifying the indicator. As you would expect, just setting a style sheet has no effect until it gets a chance to repaint and setting it twice (reverting to the original style) accomplished nothing.

            1 Reply Last reply
            0
            • M mcosta

              HI and welcome to devnet,

              I'm not sure to fully understand your problem but you can can force the redraw calling QWidget::repaint()

              J Offline
              J Offline
              Jeff Andle
              wrote on last edited by
              #6

              @mcosta

              The widget is a subclass of QLabel that caches a style.
              My setStyle function is getting called and is executing this:
              case ST_GR:
              setStyleSheet("color: white; background-color: green");
              printf("Paint it green\n");
              break;

              The calling location is calling repaint to no result so, with a little more reading, I tried forcing update enable, still to no result.

              if (ui && 0 < len && Slave >= 0 && Slave < MAX_SLAVES)
              {
                  ui->leRxData->setStyle(ST_GR);
                  int enabled = ui->leRxData->updatesEnabled();
                  if (!enabled)
                      setUpdatesEnabled(true);
                  ui->leRxData->repaint();
                  printf("force to paint it green\n");
                  if (!enabled)
                      setUpdatesEnabled(enabled);
              

              However, on failures I do get a red light using a timer.

              {
                  if (tID_RxD)
                      killTimer(tID_RxD);
              
                  ui->leRxData->setStyle(ST_RD);
                  tID_RxD = startTimer(200);
                  return 0;
              }
              

              Now that I have my update time manageable I could flash green on a timer after I return, but at this point the stubborn scholar in me needs to know why this doesn't work...

              1 Reply Last reply
              0
              • J Jeff Andle

                I have a section of code that processes a data packet. I want to flash a green "led" in the status bar to show that the data was received. The code below does not flash it. This makes sense since the UI never gets the processor (Arm9) to redraw the widget. Even a sleep there does not yield to the redraw. By the time it redraws I have reset the style sheet.

                void process ()
                {
                //QLabel leRxData;
                ...
                ui->leRxData->setStyleSheet(...); // make the label be a green indicator
                QThread::msleep (20);
                ...
                // process the data
                ...
                ui->leRxData->setStyleSheet(...); // make the label be an unlit indicator
                retuen;
                }

                J Offline
                J Offline
                Jeff Andle
                wrote on last edited by
                #7

                @Jeff-Andle No effect from any alterations to this. I could do the processing in a thread but the effort of mutexing all the variables that would be shared far exceeds the need to do this.

                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