Unsolved qlabel not changing dynamically
-
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 addedqDebug() << 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 asnew 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. -
@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:
- Did you use Qt Designer, or did you write pure C++ code?
- How did you add your QLabel to the QGroupBox?
-
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); }
-
Your code you show now don't use myLabel at all ...
-
Ugh, forgot the other half there. I've updated that post to show the declaration of the QLabel in question.
-
Is materialLayout applied to a widget?
-
I still don't see where myLabel comes from and where you initialize it.
-
@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().
-
@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.
-
@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 howmaterialLayout
is applied to the tab, or where/when the connection is made.