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



  • 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;
    }



  • HI and welcome to devnet,

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


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you trying to do something like QLed ?



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



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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.