[Solved]How to promote the QMainWindow(the base window) created by the Qt Designer?



  • OS : win7 64
    Qt ver : Qt5.3(compiled by ourself)
    compiler : vc2008

    • Purpose : Customize the closeEvent of the QMainWindow
    • My solution : define another main window which inherit QMainWindow and override the closeEvent, called it "main_window_gui"
    • Problem :

    Cannot promote the main window to main_window_gui

    Is it possible for me to customize the closeEvent without inheritance?

    Thank you very much


  • Moderators

    You don't need to promote the main window manually.
    It's done for you by default. If the class was created using the wizard then you already have the .ui, .h and .cpp files. the .h/.cpp defines a subclass of QMainWindow (by default named MainWindow) and you can customize it the way you want.

    To modify the close behavior without touching the main window you can installEventFilter() on it and in the event filtering class check for QEvent::Close type and modify the behavior there. But to be honest handling it directly in the main window class is a cleaner solution.



  • [quote author="Chris Kawa" date="1425033441"]You don't need to promote the main window manually.
    It's done for you by default. If the class was created using the wizard then you already have the .ui, .h and .cpp files. the .h/.cpp defines a subclass of QMainWindow (by default named MainWindow) and you can customize it the way you want.

    To modify the close behavior without touching the main window you can installEventFilter() on it and in the event filtering class check for QEvent::Close type and modify the behavior there. But to be honest handling it directly in the main window class is a cleaner solution.[/quote]

    Ah, you are correct, I should not promote the MainWindow, thanks a lot.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.