PDA

View Full Version : QMainWindow inside another widget



DanFessler
23rd August 2010, 00:13
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

ChrisW67
23rd August 2010, 01:52
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.

DanFessler
23rd August 2010, 05:54
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

ChrisW67
23rd August 2010, 08:14
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.




#include "thingytabinnerwindow.h"

MainWindow::MainWindow(...) {
setupUi(this); // the main window's Designer UI
...
// Patch in your inner window using the Designer created class
ThingyTabInnerWindow *tTIW = new ThingyTabInnerWindow(this);
ui->tabWidget->addTab(tTIW, tr("Thingy Tab Heading"));
// connect any inner window signals to slots as needed
...
}

DanFessler
23rd August 2010, 21:58
This was extremely useful. Thank you so much.