QWidget's child show doesn't work
-
I have a strange problem:
My MainWindow is QWidget type and its constructor is like that:...............
loggingWidget = new QWidget;
loggingWidget->setGeometry(0,0,1920,1080);
loggingWidget->setStyleSheet("background-image: url(FinalOutput_01_10.png); border: none;");(1) QWidget *rulesWidget = new QWidget(loggingWidget);
rulesWidget->setGeometry(200,200,1020,680);
rulesWidget->setStyleSheet("background-image: url(FinalOutput.png); border: none;");rulesWidget->show();
This operates OK.
But when I inherite QWidget into RulesWidget class and line (1) is:
RulesWidget *rulesWidget = new RulesWidget(loggingWidget);that show() doesn't work.
definition of RulesWidget:
class RulesWidget : public QWidget
{
Q_OBJECT
public:
explicit RulesWidget(QWidget *parent = nullptr);
......implementation
RulesWidget::RulesWidget(QWidget *parent) : QWidget(parent)
{}
-
I have a strange problem:
My MainWindow is QWidget type and its constructor is like that:...............
loggingWidget = new QWidget;
loggingWidget->setGeometry(0,0,1920,1080);
loggingWidget->setStyleSheet("background-image: url(FinalOutput_01_10.png); border: none;");(1) QWidget *rulesWidget = new QWidget(loggingWidget);
rulesWidget->setGeometry(200,200,1020,680);
rulesWidget->setStyleSheet("background-image: url(FinalOutput.png); border: none;");rulesWidget->show();
This operates OK.
But when I inherite QWidget into RulesWidget class and line (1) is:
RulesWidget *rulesWidget = new RulesWidget(loggingWidget);that show() doesn't work.
definition of RulesWidget:
class RulesWidget : public QWidget
{
Q_OBJECT
public:
explicit RulesWidget(QWidget *parent = nullptr);
......implementation
RulesWidget::RulesWidget(QWidget *parent) : QWidget(parent)
{}
@Milosz said in QWidget's child show doesn't work:
My MainWindow is QWidget type
I thought it had to be
QMainWindow
type?loggingWidget = new QWidget;
Where is its parent specified, or what is it added to?
I don't know if these are relevant to your issue, but I wouldn't mind understanding them anyway...
-
Ok,
so I show all the codeMainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{this->setWindowFlags(Qt::CustomizeWindowHint); this->setGeometry(0,0,1920, 1080); loggingWidget = new QWidget; loggingWidget->setGeometry(0,0,1920,1080); loggingWidget->setStyleSheet("background-image: url(Ekran_01_FinalOutput_01_10.png); border: none;"); RulesWidget *rulesWidget = new RulesWidget(loggingWidget); rulesWidget->setGeometry(200,200,1020,680); rulesWidget->setStyleSheet("background-image: url(Regulamin_FinalOutput.png); border: none;"); rulesWidget->show(); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(loggingWidget); setLayout(mainLayout);
}
and definition of MainWindow
class MainWindow : public QWidget
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
QWidget *loggingWidget;
};
-
Ok,
so I show all the codeMainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{this->setWindowFlags(Qt::CustomizeWindowHint); this->setGeometry(0,0,1920, 1080); loggingWidget = new QWidget; loggingWidget->setGeometry(0,0,1920,1080); loggingWidget->setStyleSheet("background-image: url(Ekran_01_FinalOutput_01_10.png); border: none;"); RulesWidget *rulesWidget = new RulesWidget(loggingWidget); rulesWidget->setGeometry(200,200,1020,680); rulesWidget->setStyleSheet("background-image: url(Regulamin_FinalOutput.png); border: none;"); rulesWidget->show(); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(loggingWidget); setLayout(mainLayout);
}
and definition of MainWindow
class MainWindow : public QWidget
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
QWidget *loggingWidget;
};
@Milosz
At least that makes sense now!Again, I don't know, but you call
rulesWidget->show();
before you have ever added it (or anything) to the main window. I wouldn't even try to do that, seems real odd to me, can a widget deal withshow()
when it's not anywhere on the page? Does it make any difference if you put that as the very last line? -
I would guess you have not implemented sizeHint() and therefore QWidget::sizeHint() is called which simply returns and invalid size since it doesn't know better.
-
I would guess you have not implemented sizeHint() and therefore QWidget::sizeHint() is called which simply returns and invalid size since it doesn't know better.
@Christian-Ehrlicher No effect.
:-(