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::setText() not responding properly
QtWS25 Last Chance

QLabel::setText() not responding properly

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlabelsettext
7 Posts 2 Posters 1.3k 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.
  • S Offline
    S Offline
    surajj4837
    wrote on 24 May 2021, 06:02 last edited by surajj4837
    #1

    I m trying to modify the text of a QLabel object, I want to show the count in label object's text.
    Following is what I tried:

    ui->Frame_ID->setText("1");
    .
    .
    .
    ui->Frame_ID->setText(" ");
    ui->Frame_ID->setText("2");
    

    But after the last line the text on label shows both values overlapped. ui->Frame_ID->setText(" ") did not clear the previous value. Apart from that I also tried ui->Frame_ID->clear(); but the output was same.

    J 1 Reply Last reply 24 May 2021, 06:42
    0
    • S surajj4837
      24 May 2021, 06:02

      I m trying to modify the text of a QLabel object, I want to show the count in label object's text.
      Following is what I tried:

      ui->Frame_ID->setText("1");
      .
      .
      .
      ui->Frame_ID->setText(" ");
      ui->Frame_ID->setText("2");
      

      But after the last line the text on label shows both values overlapped. ui->Frame_ID->setText(" ") did not clear the previous value. Apart from that I also tried ui->Frame_ID->clear(); but the output was same.

      J Offline
      J Offline
      JonB
      wrote on 24 May 2021, 06:42 last edited by
      #2

      @surajj4837
      QLabel::setText() does reset the text to the new value, completely discarding the previous value, and clear() does clear it. No idea what you mean by "shows both values overlapped". Show a screenshot, and it hardly needs saying that for a question like this you must state your platform and what version of Qt you are using.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        surajj4837
        wrote on 24 May 2021, 07:08 last edited by
        #3

        I m using Qt 5.13.2 in Ubuntu 20.04.
        In following screenshot, top left corner shows the label I want to modify. The frame numbers are printed on each other (0, 1 and 2).

        b465594c-1c68-477e-b71d-961cb88a884c-image.png
        Following code sets the values in the label text:

        ui->Frame_ID->setText(" ");     //Clear the text
        
        std::string text = "Frame No: " + std::to_string(CurrentFrame);     //Frame new text
        
        ui->Frame_ID->setText(QString(text.c_str()));       //Set new text
        
        J 1 Reply Last reply 24 May 2021, 08:03
        0
        • S surajj4837
          24 May 2021, 07:08

          I m using Qt 5.13.2 in Ubuntu 20.04.
          In following screenshot, top left corner shows the label I want to modify. The frame numbers are printed on each other (0, 1 and 2).

          b465594c-1c68-477e-b71d-961cb88a884c-image.png
          Following code sets the values in the label text:

          ui->Frame_ID->setText(" ");     //Clear the text
          
          std::string text = "Frame No: " + std::to_string(CurrentFrame);     //Frame new text
          
          ui->Frame_ID->setText(QString(text.c_str()));       //Set new text
          
          J Offline
          J Offline
          JonB
          wrote on 24 May 2021, 08:03 last edited by
          #4

          @surajj4837
          This seems to me to be something to do with whatever background your label is on. Out of interest, what happens to the visual label if you simple hide/delete the label?

          S 1 Reply Last reply 24 May 2021, 08:26
          0
          • J JonB
            24 May 2021, 08:03

            @surajj4837
            This seems to me to be something to do with whatever background your label is on. Out of interest, what happens to the visual label if you simple hide/delete the label?

            S Offline
            S Offline
            surajj4837
            wrote on 24 May 2021, 08:26 last edited by surajj4837
            #5

            @JonB Actually you are right, in the background I m using QVTKWidget which is causing this overlap display, when I moved that QLabel object to some other place on an empty background and also on another QLabel object, the operation is happening fine. There seems to be an uknown issue with QVTKWidget.

            J 1 Reply Last reply 24 May 2021, 08:37
            0
            • S surajj4837
              24 May 2021, 08:26

              @JonB Actually you are right, in the background I m using QVTKWidget which is causing this overlap display, when I moved that QLabel object to some other place on an empty background and also on another QLabel object, the operation is happening fine. There seems to be an uknown issue with QVTKWidget.

              J Offline
              J Offline
              JonB
              wrote on 24 May 2021, 08:37 last edited by JonB
              #6

              @surajj4837 said in QLabel::setText() not responding properly:

              QVTKWidget

              I thought so! I know nothing about "QVTKWidget". Is it old/deprecated? A random post I came across suggesting problems with widgets on it is http://vtk.1045678.n5.nabble.com/QVTKWidget-vs-QVTKOpenglWidget-vs-QVTKWidget2-td5748605.html . Are you supposed to move to some "QVTKOpenglWidget" or "QVTKWidget2"?

              S 1 Reply Last reply 24 May 2021, 09:11
              0
              • J JonB
                24 May 2021, 08:37

                @surajj4837 said in QLabel::setText() not responding properly:

                QVTKWidget

                I thought so! I know nothing about "QVTKWidget". Is it old/deprecated? A random post I came across suggesting problems with widgets on it is http://vtk.1045678.n5.nabble.com/QVTKWidget-vs-QVTKOpenglWidget-vs-QVTKWidget2-td5748605.html . Are you supposed to move to some "QVTKOpenglWidget" or "QVTKWidget2"?

                S Offline
                S Offline
                surajj4837
                wrote on 24 May 2021, 09:11 last edited by surajj4837
                #7

                @JonB Thanks, this is new information for me. Actually the "QVTKWidget" was sufficing my problem to display point cloud data. For now it is working properly because I m using VTK 7.0. It seems post VTK 8.0, the QVTKOpenglWidget needs to be used.

                1 Reply Last reply
                0

                5/7

                24 May 2021, 08:26

                • Login

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