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. Creating a window that's tied to parent QMainWindow, has a separate taskbar button and minimize button

Creating a window that's tied to parent QMainWindow, has a separate taskbar button and minimize button

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.6k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I need to create a window that accepts a parent QMainWindow (so that it closes automatically when main window is closed), has a separate task bar button, minimize button, and is displayed with show(), not exec(). Should I use QDialog or QWidget, and what window flags should I set? I'm mostly talking about Windows, but need this window to look OK and have minimize button on Mac OS as well.
    Or should I maybe use a second QMainWindow for this?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      just use a simple QWidget and set the parent widget to your QMainWindow.
      And just set the window flags to Qt::Window

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        There's no taskbar button in this case. I only get a button if I set parent to null, but I don't want to do that either.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          ok and why not just holding a pointer to the window and deleting it in your main window destructor?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            That's exactly what I'm trying to avoid. There can be indefinite number of these windows created during application's life, holding a pointer means not deleting the window when it's no longer needed, which in turn effectively means memory leak.

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              ok then the other way around:
              When you would set your mainwindow as the parent of the new subwindow you connect the mainwindow's destroyed() signal to the subwindow's deleteLater() slot instead.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Violet Giraffe
                wrote on last edited by
                #7

                Thanks, that didn't cross my mind. However, if I first close mainwindow and then the helper window, mainwindow's destroyed() isn't called until helper window is closed.
                I already have closeEvent() reimplemented in my mainwindow, so it will be easy to add a special signal that will be emitted in closeEvent().

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @
                  QWidget::setAttribute(Qt::WA_DeleteOnClose);
                  @

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vezprog
                    wrote on last edited by
                    #9

                    You could get the 'close()' event on the dialog and trigger a slot in the main window, so when an instance of the dialog closes, you could get the 'sender()' object in your slot and delete it.

                    Otherwise, create a list of dialog's as you create them...and delete them when you close the application. You might not want to keep them all in memory though.

                    There are many ways to accomplish what you are trying to do, you just have to choose which way is convenient in your code.

                    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