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. How do I make a QLabel Blink?
QtWS25 Last Chance

How do I make a QLabel Blink?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt6.1.2qtimerqlabelmainwindowwindows 10
5 Posts 4 Posters 1.7k Views
  • 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.
  • D Offline
    D Offline
    DougyDrumz2
    wrote on last edited by
    #1

    The consensus is evidently to l hide and show a QLabel using a Qtimer. I tried this using a single-shot Qtimer with a QLabel on a MainWidget using Qt 6.1.2 running on Windows 10. This didn't work for me. Here's what I did:

    void BJTMainWindow::showYouBust()
    {
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
    }
    
    void BJTMainWindow::updateCaption()
    {
        if (myBjtMW->youBustLabel->isVisible())
        {
            myBjtMW->youBustLabel->hide();
        }
        else
        {
            myBjtMW->youBustLabel->show();
        }
    }
    

    After a delay (of 15 seconds?). The label shows once. I ran this through gdb. The hides and shows are definitely being called. What am I missing?

    raven-worxR JonBJ 2 Replies Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @DougyDrumz2 said in How do I make a QLabel Blink?:
      QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
      QTimer::singleShot(3100, this, &BJTMainWindow::updateCaption);
      QTimer::singleShot(3200, this, &BJTMainWindow::updateCaption);
      QTimer::singleShot(3300, this, &BJTMainWindow::updateCaption);
      QTimer::singleShot(3400, this, &BJTMainWindow::updateCaption);

      1 Reply Last reply
      1
      • D DougyDrumz2

        The consensus is evidently to l hide and show a QLabel using a Qtimer. I tried this using a single-shot Qtimer with a QLabel on a MainWidget using Qt 6.1.2 running on Windows 10. This didn't work for me. Here's what I did:

        void BJTMainWindow::showYouBust()
        {
            QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
            QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
            QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
            QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
            QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        }
        
        void BJTMainWindow::updateCaption()
        {
            if (myBjtMW->youBustLabel->isVisible())
            {
                myBjtMW->youBustLabel->hide();
            }
            else
            {
                myBjtMW->youBustLabel->show();
            }
        }
        

        After a delay (of 15 seconds?). The label shows once. I ran this through gdb. The hides and shows are definitely being called. What am I missing?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @DougyDrumz2 said in How do I make a QLabel Blink?:

        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
        QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);

        this calls the method 5 times in a row after 3 seconds, not after 3,6,9,12,15s as you expect.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • D Offline
          D Offline
          DougyDrumz2
          wrote on last edited by
          #4

          Awesome. Thanks

          1 Reply Last reply
          0
          • D DougyDrumz2

            The consensus is evidently to l hide and show a QLabel using a Qtimer. I tried this using a single-shot Qtimer with a QLabel on a MainWidget using Qt 6.1.2 running on Windows 10. This didn't work for me. Here's what I did:

            void BJTMainWindow::showYouBust()
            {
                QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
                QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
                QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
                QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
                QTimer::singleShot(3000, this, &BJTMainWindow::updateCaption);
            }
            
            void BJTMainWindow::updateCaption()
            {
                if (myBjtMW->youBustLabel->isVisible())
                {
                    myBjtMW->youBustLabel->hide();
                }
                else
                {
                    myBjtMW->youBustLabel->show();
                }
            }
            

            After a delay (of 15 seconds?). The label shows once. I ran this through gdb. The hides and shows are definitely being called. What am I missing?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @DougyDrumz2 said in How do I make a QLabel Blink?:

            The consensus is evidently to l hide and show a QLabel

            Not my "consensus :) So far as I am aware, hiding can cause different layout redraw in at least some circumstances. I retain visibility but toggle foreground color to QColor(Qt::transparent) or toggle alpha color value between 255 (opaque) and 0 (transparent) on palette QPalette::setColor(QPalette::Text, colour).

            Also, creating multiple QTimer::singleShot()s doesn't scale very well if you want to change the number of flashes or the interval between. Or of you have multiple labels to blink and you'd like them all to be "in sync". I use one regular repeating QTimer with a "countdown" and cancellation when it reaches 0.

            Up to you on both of these.

            1 Reply Last reply
            2

            • Login

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