Answer the question
In order to leave comments, you need to log in
Why can't I add my Widget to Layout (Qt)?
I wrote such a simple Widget:
class but_indicate : public QWidget
{
Q_OBJECT
public:
explicit but_indicate(QWidget *parent = nullptr);
private:
QLabel *lb1, *lb2;
public slots:
void buttonPressed();
void buttonReleased();
};
but_indicate::but_indicate(QWidget *parent) : QWidget(parent)
{
QHBoxLayout* tbLO = new QHBoxLayout;
lb1 = new QLabel("Simple button is not pressed.");
lb1->setFrameStyle(QFrame::Box);
lb1->setLineWidth(1);
lb2 = new QLabel("Toggle button is not pressed.");
lb2->setFrameStyle(QFrame::Box);
lb2->setLineWidth(1);
tbLO->addWidget(lb1);
tbLO->addWidget(lb2);
setLayout(tbLO);
}
but_indicate* b = new but_indicate;
b->show();
QVBoxLayout* mainLO = new QVBoxLayout;
mainLO->addWidget(but_indicate); //вот тут ошибка
Answer the question
In order to leave comments, you need to log in
I accidentally wrote the name of the class instead of the name of the variable in the last line, there were no problems in the implementation of the class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question