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. QMainWindow inside a widget, can be done or is not correct?

QMainWindow inside a widget, can be done or is not correct?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 8.1k 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.
  • deleted57D Offline
    deleted57D Offline
    deleted57
    wrote on last edited by
    #1

    Hi all

    I would like to "embed" a QMainWindow inside a widget for allow me to use the QDocWidget feature only inside the widget itself. Looking around I found some tricks it seem allow to make it (not tested yet). Basically the trick consist in set the widget flag to the QMainWindow derived object as explained here:

    http://stackoverflow.com/questions/6344886/qt4-placing-qmainwindow-instance-inside-other-qwidget-qmainwindow

    However, before start implementation, my doubt is about the correctness to make such operation. I mean, is correct to use an object designed to be the top level window class inside a child window? This case will have two QMainWindow objects. Could this "redoundace" cause some unexpeced bugs?

    Thank you for your help

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      A QMainWindow is also just a very complex widget, so yes, you could use multiple QMainWindow widgets. I don't think I would recommend it. Never given it any thought ;-)

      Greetz, Jeroen

      1 Reply Last reply
      0
      • deleted57D Offline
        deleted57D Offline
        deleted57
        wrote on last edited by
        #3

        Hi

        Thank you for reply

        Than there is no problem but why you would not reccoment make such thing? Is the doubt I have. Could be an incorrect use of this class?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thEClaw
          wrote on last edited by
          #4

          I am writing a program which is using several QMainWindows as pages of a QTabWidget, since I wanted to have the features of QDockWidget available. It works perfectly.

          As stated, QMainWindow is just a subclass of QWidget, so you can do with it whatever you like. If you look at the classes functions, you'll notice that none of them actually need the QMainWindow to be the top-level window. There is merely additional functionality, it is mostly about Toolbars, Menubars and Dockwidgets.

          Also, the only other way to use dockwidgets would be very complicated and probably somewhat error-prone. You would have to rewrite half of QMainWindow in a standard QWidget-subclass. And I am not sure if you could gain anything from that, at all.

          1 Reply Last reply
          0
          • deleted57D Offline
            deleted57D Offline
            deleted57
            wrote on last edited by
            #5

            Hi thEClaw

            Thank you for your reply, very useful. By the way you used the trick suggested in the link I posted before for have QMainWindows working as child window?

            Thank you

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thEClaw
              wrote on last edited by
              #6

              I am not sure which "trick" you mean. Setting the QMainWindows flags to Qt::Widget instead of Qt::Window? I didn't do that.

              1 Reply Last reply
              0
              • deleted57D Offline
                deleted57D Offline
                deleted57
                wrote on last edited by
                #7

                Hi

                Based to the advises explained in the link above the proble is the following:

                _QMainWindow sets its window type to Qt::Window so that it will be in an independent window even if it has a parent (you can confirm this by calling show() on your QMainWindow, and you will see it in its own window). Try adding the line

                window->setWindowFlags(Qt::Widget);

                after you construct the QMainWindow._

                Anyway if it work for you this is not very important. I was sure it can be done, my doub are mainly connected to the "correctness" using this class in such way.

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

                  [quote author="Suppaman" date="1378980192"] I was sure it can be done, my doub are mainly connected to the "correctness" using this class in such way.[/quote]
                  There is nothing wrong in embedding QMainWindow as a child-widget. Although the name may be a bit confusing though. But it's a simple widget which has features which are common as a starting point of your application, the main 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
                  • deleted57D Offline
                    deleted57D Offline
                    deleted57
                    wrote on last edited by
                    #9

                    OK, thank you very much for the clarification. My doub is disappeared now! :)

                    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