Qwidget's size not get updated ?
-
Hi, I got a custom QWidget, then I set it as my QMainWindow's menubar using setMenuWidget, but the width was not get updated as I assumed it should be the same as the width of the Mainwindow, the statusBar also has the same issue as well, but both of them look stretched out to align with the Width of my MainWindow , thanks for the help!
TitleBar = new CustomizedTitleBar(this); this->setWindowFlags(Qt::FramelessWindowHint); this->setMenuWidget(TitleBar); qDebug()<<TitleBar->width()<<TitleBar->parentWidget()->width(); //prints 453 /prints 1200
-
Hi, I got a custom QWidget, then I set it as my QMainWindow's menubar using setMenuWidget, but the width was not get updated as I assumed it should be the same as the width of the Mainwindow, the statusBar also has the same issue as well, but both of them look stretched out to align with the Width of my MainWindow , thanks for the help!
TitleBar = new CustomizedTitleBar(this); this->setWindowFlags(Qt::FramelessWindowHint); this->setMenuWidget(TitleBar); qDebug()<<TitleBar->width()<<TitleBar->parentWidget()->width(); //prints 453 /prints 1200
@junzhe-fan said in Qwidget's size not get updated ?:
but both of them look stretched out to align with the Width of my MainWindow
So are you saying they do appear correctly?
Printing out widget widths/heights e.g. just after creating them does not deliver meaningful results. Dimensions only get set correctly after a widget has been shown, as that is when Qt calculates them.