Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qlabel not changing dynamically
Qt 6.11 is out! See what's new in the release blog

qlabel not changing dynamically

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 5.0k Views 1 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
    johnby
    wrote on last edited by johnby
    #11

    I definitely see the text that I'm expecting from the passed in parameter (const Material &material) when printing to console.

    I even write ...

    materialLabel->setText("testing");
    

    and nothing changes in the tab.

    Update:
    I just added

    qDebug() << materialLabel->parentWidget() << materialLabel->isVisible() << materialLabel->pos();
    

    And got ...

    QGroupBox(0x558878be3740) false QPoint(0,0)
    

    It is in a QGroupBox, but the isVisible says false, so I added setVisible(true) to the QLabel, but nothing changed. I can see all qwidgets within the tab that I'm expecting to see, except for this label which is initialized as new QLabel(); Which I believe means empty. I did initialize w/ a string and that of course displayed the label initialized with the string, but still, the value never updates dynamically when the slot is called.

    So, don't quite understand why the labels isVisible is showing false, because I can see it when I give it a string to init with.

    JKSHJ 1 Reply Last reply
    0
    • J johnby

      I definitely see the text that I'm expecting from the passed in parameter (const Material &material) when printing to console.

      I even write ...

      materialLabel->setText("testing");
      

      and nothing changes in the tab.

      Update:
      I just added

      qDebug() << materialLabel->parentWidget() << materialLabel->isVisible() << materialLabel->pos();
      

      And got ...

      QGroupBox(0x558878be3740) false QPoint(0,0)
      

      It is in a QGroupBox, but the isVisible says false, so I added setVisible(true) to the QLabel, but nothing changed. I can see all qwidgets within the tab that I'm expecting to see, except for this label which is initialized as new QLabel(); Which I believe means empty. I did initialize w/ a string and that of course displayed the label initialized with the string, but still, the value never updates dynamically when the slot is called.

      So, don't quite understand why the labels isVisible is showing false, because I can see it when I give it a string to init with.

      JKSHJ Online
      JKSHJ Online
      JKSH
      Moderators
      wrote on last edited by
      #12

      @johnby Is is possible that myLabel and the label that you see on screen are actually 2 different objects?

      Please show us how you initialized the QGroupBox and the QLabel. In particular:

      1. Did you use Qt Designer, or did you write pure C++ code?
      2. How did you add your QLabel to the QGroupBox?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      1
      • J Offline
        J Offline
        johnby
        wrote on last edited by johnby
        #13

        It's all C++ code, no designer work.
        Here's how I initialize the label and group in the ctor of my tab widget.

        class MaterialsTab : public QWidget
        {
            Q_OBJECT
            
            private:
                QLabel *materialLabel;
                QVBoxLayout *materialLayout;
            
                // ...
            
            public:
                explicit MaterialsTab(QWidget *parent = 0);
            
            public slots:
                void editMaterial(const Material &material);
        }
        
        MaterialsTab::MaterialsTab(QWidget *parent) : QWidget(parent)
        {
            materialLabel = new QLabel();
            materialLabel->setVisible(true); // shouldn't need this, but tried anyway
        
            // ...
        
            materialLayout = new QVBoxLayout;
        
            // ...
            QGroupBox *nameGroup = new QGroupBox;
        
            QGridLayout *layout = new QGridLayout;
            layout->addWidget(materialLabel, 0, 1, 1, 3);
            // ...
        
            nameGroup->setLayout(layout);
        
            materialLayout->addWidget(nameGroup);
        }
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #14

          Your code you show now don't use myLabel at all ...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • J Offline
            J Offline
            johnby
            wrote on last edited by johnby
            #15

            Ugh, forgot the other half there. I've updated that post to show the declaration of the QLabel in question.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #16

              Is materialLayout applied to a widget?

              J 1 Reply Last reply
              1
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #17

                I still don't see where myLabel comes from and where you initialize it.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                J 1 Reply Last reply
                0
                • C ChrisW67

                  Is materialLayout applied to a widget?

                  J Offline
                  J Offline
                  johnby
                  wrote on last edited by
                  #18

                  @ChrisW67 said in qlabel not changing dynamically:

                  Is materialLayout applied to a widget?

                  Yes, materlalLayout gets applied to the tab, and again, all this is fine. I have more widgets in that mix and they all show up. even materialLabel displays fine w/ whatever it's initialized with. It just doesn't update dynamically when my slot gets called and does a setText().

                  JKSHJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    I still don't see where myLabel comes from and where you initialize it.

                    J Offline
                    J Offline
                    johnby
                    wrote on last edited by
                    #19

                    @Christian-Ehrlicher said in qlabel not changing dynamically:

                    I still don't see where myLabel comes from and where you initialize it.

                    Ah, you're not looking at the latest post where things are renamed and I've given all the details. Forget anything prefixed w/ my.

                    1 Reply Last reply
                    0
                    • J johnby

                      @ChrisW67 said in qlabel not changing dynamically:

                      Is materialLayout applied to a widget?

                      Yes, materlalLayout gets applied to the tab, and again, all this is fine. I have more widgets in that mix and they all show up. even materialLabel displays fine w/ whatever it's initialized with. It just doesn't update dynamically when my slot gets called and does a setText().

                      JKSHJ Online
                      JKSHJ Online
                      JKSH
                      Moderators
                      wrote on last edited by JKSH
                      #20

                      @johnby said in qlabel not changing dynamically:

                      Yes, materlalLayout gets applied to the tab, and again, all this is fine. I have more widgets in that mix and they all show up. even materialLabel displays fine w/ whatever it's initialized with. It just doesn't update dynamically when my slot gets called and does a setText().

                      Please provide a minimal compilable example (including main.cpp) which contains this issue -- copy your project and remove the parts that are not involved with the issue. It is difficult to troubleshoot the code when bits are missing. For example, we can't see how materialLayout is applied to the tab, or where/when the connection is made.

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      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
                      • Unsolved