new class inherited from QLabel not showing in parent window
Unsolved
General and Desktop
-
Hi everyone,
I created a new class inherited from QLabel.#ifndef WANDERLABEL_H #define WANDERLABEL_H #include <QLabel> #include <QTimer> class wanderLabel : public QLabel { Q_OBJECT public: wanderLabel(); private: QTimer* timer; private slots: void moveLabel(); }; #endif // WANDERLABEL_H
in my cpp I added:
Matrix::Matrix(QWidget *parent) : QMainWindow(parent) { setGeometry(400, 300, 400, 400); QLabel* test; test = new QLabel(this); test->setText("test"); wanderLabel* wanderer; wanderer = new wanderLabel(this); wanderer->setText("1"); //wanderer->show(); }
while any QLabel instance is correctly showing,
creating an instance of wanderlabel gives me the error: no matching constructor.
So I changed the constructor:
wanderLabel(QWidget *parent = nullptr);
now, after addingshow()
it shows, but not in the widget, but as a new widget on the main screen.
What am I missing? -
@herrgross said in new class inherited from QLabel not showing in parent window:
So I changed the constructor:
wanderLabel(QWidget *parent = nullptr);Did you pass the
parent
pointer to the super class? egwanderLabel::wanderLabel(QWidget *parent = nullptr) : QLabel(parent) ///< this part? { }
Cheers.
-
@Paul-Colby
that's what it was! thank you!!