Results 1 to 5 of 5

Thread: QMainWindow inside another widget

  1. #1

    Default QMainWindow inside another widget

    Hello, I'm very new to Qt. I'm trying to replicate the functionality of a mockup of mine for a tool i'm developing. This would call for dockwidgets and toolbars to be inside a tabwidget. From what i've read, the only widget that can hold dockables and toolbars is the main-window and some have suggested to somehow make the mainwindow a child of another widget (in my case, a tabwidget). But the answers were never well defined for someone new to qt. Could someone please give a detailed solution to this?

    I currently have a .UI form designed with a tabwidget. Would it be possible to design another .UI document that contained another mainwindow to be inserted into these tabs from my first .ui file?

    here is my mockup for reference:
    http://danfessler.com/dump/mock_modanim.png

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMainWindow inside another widget

    You can certainly place a QMainWindow inside another widget; I use them inside MDI child windows for example.

    You can design the main window separately and install it as a child of another widget in code. I expect you could also embed it in its parent by placing a QWidget in the parent and using the Promote feature to change its class.

  3. #3

    Default Re: QMainWindow inside another widget

    and install it as a child of another widget in code
    thanks for the reply. I would greatly appreciate someone walking me through this part. Assume you have just created a new Qt GUI project within qt creator and added a tabwidget to the existing mainwindow.ui

    Thanks
    -Dan

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMainWindow inside another widget

    Exactly how you do the plumbing depends on exactly how you want things arranged. However, it's something along these lines:
    • Open your project in Qt Creator
    • "Add New...", "Designer Form Class", type is "Main Window", and provide some names to add another QMainWindow derivative to your project. I'll use a class called ThingyTabInnerWindow as an example.
    • Design the new inner form.
    • Go to the source for the UI class that contains your tab widget (e.g. MainWindow)
    • In the constructor (or somewhere else that makes sense) try something like the code below. It's exactly the same as adding any other widget to a tab widget.


    Qt Code:
    1. #include "thingytabinnerwindow.h"
    2.  
    3. MainWindow::MainWindow(...) {
    4. setupUi(this); // the main window's Designer UI
    5. ...
    6. // Patch in your inner window using the Designer created class
    7. ThingyTabInnerWindow *tTIW = new ThingyTabInnerWindow(this);
    8. ui->tabWidget->addTab(tTIW, tr("Thingy Tab Heading"));
    9. // connect any inner window signals to slots as needed
    10. ...
    11. }
    To copy to clipboard, switch view to plain text mode 

  5. #5

    Default Re: QMainWindow inside another widget

    This was extremely useful. Thank you so much.

Similar Threads

  1. resizing widget inside QScrollArea
    By mastupristi in forum Newbie
    Replies: 4
    Last Post: 16th July 2009, 19:29
  2. switch a QWidget inside a QMainWindow to fullscreen
    By koenux in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2009, 21:25
  3. Shell inside QT WIdget
    By pshah.mumbai in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2008, 17:57
  4. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 13:00
  5. Central Widget of QMainWindow
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2006, 18:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.