Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to promote the QMainWindow(the base window) created by the Qt Designer?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved