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. Change a label's text when a variable changes
Forum Update on Monday, May 27th 2025

Change a label's text when a variable changes

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 986 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.
  • R Offline
    R Offline
    rtvideo
    wrote on 17 Sept 2020, 16:37 last edited by
    #1

    I currently have this label:

     ui->label->setText("<font color='red'>Changing...");
    

    But i want it to output "Changing...X/10" With X being a certain variable that is being incremented in a loop, How would I pass in the int variable to the text

    J 1 Reply Last reply 17 Sept 2020, 16:43
    0
    • R rtvideo
      17 Sept 2020, 16:37

      I currently have this label:

       ui->label->setText("<font color='red'>Changing...");
      

      But i want it to output "Changing...X/10" With X being a certain variable that is being incremented in a loop, How would I pass in the int variable to the text

      J Offline
      J Offline
      JonB
      wrote on 17 Sept 2020, 16:43 last edited by JonB
      #2

      @rtvideo
      Look at the QString::arg() family of methods, like the example at https://doc.qt.io/qt-5/qstring.html#arg. There is also QString::number() for just a number alone.

      R 1 Reply Last reply 17 Sept 2020, 18:22
      4
      • J JonB
        17 Sept 2020, 16:43

        @rtvideo
        Look at the QString::arg() family of methods, like the example at https://doc.qt.io/qt-5/qstring.html#arg. There is also QString::number() for just a number alone.

        R Offline
        R Offline
        rtvideo
        wrote on 17 Sept 2020, 18:22 last edited by
        #3

        @JonB Thank you that worked great

        1 Reply Last reply
        0

        1/3

        17 Sept 2020, 16:37

        • Login

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