[Interest] How to get QMainWindow derived window to show

Jeremy Katz jeremy.k.list at gmail.com
Sat May 1 03:34:58 CEST 2021



On 30/Apr/21 15:20, Nicholas Yue wrote:
> Hi,
> 
>   I am learning and comparing the different UI I can create via Designer
> 
>   I can get the Widget to load and show up
> 
> https://github.com/nyue/QtQuestions/blob/main/Qt5/language_change/form/Form.cpp
> <https://github.com/nyue/QtQuestions/blob/main/Qt5/language_change/form/Form.cpp>
> 
>   but somehow, the MainWindow variety, I have not been able to
> 
> https://github.com/nyue/QtQuestions/blob/main/Qt5/language_change/mainwindow/MainWindow.cpp
> <https://github.com/nyue/QtQuestions/blob/main/Qt5/language_change/mainwindow/MainWindow.cpp>
> 
>   The examples and documentation I found focuses on Form/Widget but not
> MainWindow
> 
>   Any advice ?

Omit the parentWidget parameter in the call to QUiLoader::load. Layouts
handle reparenting widgets they manage.

That and using QMainWindow::setCentralWidget instead of attempting to
apply a new layout to the entire QMainWindow should be enough to display
the content of the UI file.


More information about the Interest mailing list