Qt-interest Archive, December 2007
Put a QMainWindow in a QDockWidget
Message 1 in thread
Hi Everyone,
I use QT 4.2.3 as my application GUI toolkit. But I would like
to create a QMainWindow inside a QDockWidget. Of course,
this QDockWidget belongs to the top main window of my application.
But I worried about the QT limitation. So I checked the document
but found nothing about this topic.
So I wrote source code as below. I skipped the top main window part.
Whe I run it, the dock widget created normally. But I can not see my
data inside the tableView.
Could anybody help me out ?
Regards,
Pagan
QDockWidget* m_pDockWidget = new QDockWidget(parent);
m_pDockWidget->setObjectName(QString::fromUtf8("m_pDockWidget"));
dockWidgetContents = new QWidget(m_pDockWidget);
dockWidgetContents->setObjectName(QString::fromUtf8("dockWidgetContents"));
vboxLayout1 = new QVBoxLayout(dockWidgetContents);
vboxLayout1->setSpacing(1);
vboxLayout1->setMargin(1);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
QMainWindow* window = new QMainWindow(dockWidgetContents);
window->setObjectName(QString::fromUtf8("window"));
QWidget* centralwidget = new QWidget(window);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
QVBoxLayout* vboxLayout = new QVBoxLayout(centralwidget);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(9);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
QTableView* resTableView = new QTableView(centralwidget);
resTableView->setObjectName(QString::fromUtf8("resTableView"));
vboxLayout->addWidget(resTableView);
window->setCentralWidget(centralwidget);
QMenuBar* menubar = new QMenuBar(window);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 800, 22));
window->setMenuBar(menubar);
QStatusBar* statusbar = new QStatusBar(window);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
window->setStatusBar(statusbar);
QSize winSize(300, 300);
winSize = winSize.expandedTo(window->minimumSizeHint());
window->resize(winSize);
vboxLayout1->addWidget(window);
m_pDockWidget->setWidget(dockWidgetContents);
if (NULL!=parent)
parent->addDockWidget(static_cast<Qt::DockWidgetArea>(2),
m_pDockWidget);
m_pDockWidget->setWindowTitle("Test");
m_pDockWidget->setFloating(TRUE);
QSize size(400, 400);
m_pDockWidget->resize(size);
--
[ signature omitted ]
Message 2 in thread
I've seen this type of problem before with QMainWindow. 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.
Tom
On Dec 13, 2007 2:47 AM, Pagan Chou <pagan_chou@xxxxxxxxxxxxxx> wrote:
> Hi Everyone,
> I use QT 4.2.3 as my application GUI toolkit. But I would like
> to create a QMainWindow inside a QDockWidget. Of course,
> this QDockWidget belongs to the top main window of my application.
>
> But I worried about the QT limitation. So I checked the document
> but found nothing about this topic.
>
> So I wrote source code as below. I skipped the top main window part.
>
> Whe I run it, the dock widget created normally. But I can not see my
> data inside the tableView.
>
> Could anybody help me out ?
>
> Regards,
> Pagan
>
> QDockWidget* m_pDockWidget = new QDockWidget(parent);
> m_pDockWidget->setObjectName(QString::fromUtf8("m_pDockWidget"));
> dockWidgetContents = new QWidget(m_pDockWidget);
>
>
> dockWidgetContents->setObjectName(QString::fromUtf8("dockWidgetContents"));
> vboxLayout1 = new QVBoxLayout(dockWidgetContents);
> vboxLayout1->setSpacing(1);
> vboxLayout1->setMargin(1);
> vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
>
> QMainWindow* window = new QMainWindow(dockWidgetContents);
> window->setObjectName(QString::fromUtf8("window"));
> QWidget* centralwidget = new QWidget(window);
> centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
> QVBoxLayout* vboxLayout = new QVBoxLayout(centralwidget);
> vboxLayout->setSpacing(6);
> vboxLayout->setMargin(9);
> vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
> QTableView* resTableView = new QTableView(centralwidget);
> resTableView->setObjectName(QString::fromUtf8("resTableView"));
>
> vboxLayout->addWidget(resTableView);
>
> window->setCentralWidget(centralwidget);
> QMenuBar* menubar = new QMenuBar(window);
> menubar->setObjectName(QString::fromUtf8("menubar"));
> menubar->setGeometry(QRect(0, 0, 800, 22));
> window->setMenuBar(menubar);
> QStatusBar* statusbar = new QStatusBar(window);
> statusbar->setObjectName(QString::fromUtf8("statusbar"));
> window->setStatusBar(statusbar);
>
> QSize winSize(300, 300);
> winSize = winSize.expandedTo(window->minimumSizeHint());
> window->resize(winSize);
>
> vboxLayout1->addWidget(window);
>
> m_pDockWidget->setWidget(dockWidgetContents);
>
> if (NULL!=parent)
> parent->addDockWidget(static_cast<Qt::DockWidgetArea>(2),
> m_pDockWidget);
>
> m_pDockWidget->setWindowTitle("Test");
>
> m_pDockWidget->setFloating(TRUE);
> QSize size(400, 400);
> m_pDockWidget->resize(size);
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 3 in thread
I tried what Tom told me and it works !!
I added this line :
window->setWindowFlags(Qt::Widget);
But I can not see the menu and toolbar in the dock widget. Is this the QT
spec ?
"Tom Panning" <lurchvt@xxxxxxxxx> ???
news:1dc2e45d0712130527y1ec786abw3ac7db0b6b1651d2@xxxxxxxxxxxxxx ???...
I've seen this type of problem before with QMainWindow. 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.
Tom
On Dec 13, 2007 2:47 AM, Pagan Chou <pagan_chou@xxxxxxxxxxxxxx > wrote:
Hi Everyone,
I use QT 4.2.3 as my application GUI toolkit. But I would like
to create a QMainWindow inside a QDockWidget. Of course,
this QDockWidget belongs to the top main window of my application.
But I worried about the QT limitation. So I checked the document
but found nothing about this topic.
So I wrote source code as below. I skipped the top main window part.
Whe I run it, the dock widget created normally. But I can not see my
data inside the tableView.
Could anybody help me out ?
Regards,
Pagan
QDockWidget* m_pDockWidget = new QDockWidget(parent);
m_pDockWidget->setObjectName(QString::fromUtf8("m_pDockWidget"));
dockWidgetContents = new QWidget(m_pDockWidget);
dockWidgetContents->setObjectName(QString::fromUtf8("dockWidgetContents"));
vboxLayout1 = new QVBoxLayout(dockWidgetContents);
vboxLayout1->setSpacing(1);
vboxLayout1->setMargin(1);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
QMainWindow* window = new QMainWindow(dockWidgetContents);
window->setObjectName(QString::fromUtf8("window"));
QWidget* centralwidget = new QWidget(window);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
QVBoxLayout* vboxLayout = new QVBoxLayout(centralwidget);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(9);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
QTableView* resTableView = new QTableView(centralwidget);
resTableView->setObjectName(QString::fromUtf8("resTableView"));
vboxLayout->addWidget(resTableView);
window->setCentralWidget(centralwidget);
QMenuBar* menubar = new QMenuBar(window);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 800, 22));
window->setMenuBar(menubar);
QStatusBar* statusbar = new QStatusBar(window);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
window->setStatusBar(statusbar);
QSize winSize(300, 300);
winSize = winSize.expandedTo(window->minimumSizeHint());
window->resize(winSize);
vboxLayout1->addWidget(window);
m_pDockWidget->setWidget(dockWidgetContents);
if (NULL!=parent)
parent->addDockWidget(static_cast<Qt::DockWidgetArea>(2),
m_pDockWidget);
m_pDockWidget->setWindowTitle("Test");
m_pDockWidget->setFloating(TRUE);
QSize size(400, 400);
m_pDockWidget->resize(size);
--
[ signature omitted ]
Message 4 in thread
On Dec 14, 2007 2:46 AM, Pagan Chou <pagan_chou@xxxxxxxxxxxxxx> wrote:
> I tried what Tom told me and it works !!
>
> I added this line :
> window->setWindowFlags(Qt::Widget);
>
> But I can not see the menu and toolbar in the dock widget. Is this the QT
> spec ?
>
For the menu, why are you creating your own instead of using
QMainWindow::menuBar() (although this shouldn't cause a problem), and why
are you calling setGeometry() on the menu bar? I didn't see where you added
toolbars to the QMainWindow, so I can't answer why they aren't there.
Tom
Message 5 in thread
On Thursday 13 December 2007 08:47:17 Pagan Chou wrote:
Sometimes, you need a window->show() in there.
If it doesn't work, it might help to make a limited sample (without all the
layout stuff and so on, just a main widget with a button or label on there),
and build it up from there.
Does a non-QMainWindow work in your example?
> Hi Everyone,
> I use QT 4.2.3 as my application GUI toolkit. But I would like
> to create a QMainWindow inside a QDockWidget. Of course,
> this QDockWidget belongs to the top main window of my application.
>
> But I worried about the QT limitation. So I checked the document
> but found nothing about this topic.
>
> So I wrote source code as below. I skipped the top main window part.
>
> Whe I run it, the dock widget created normally. But I can not see my
> data inside the tableView.
>
> Could anybody help me out ?
>
> Regards,
> Pagan
>
> QDockWidget* m_pDockWidget = new QDockWidget(parent);
> m_pDockWidget->setObjectName(QString::fromUtf8("m_pDockWidget"));
> dockWidgetContents = new QWidget(m_pDockWidget);
>
> dockWidgetContents->setObjectName(QString::fromUtf8("dockWidgetContents"));
> vboxLayout1 = new QVBoxLayout(dockWidgetContents);
> vboxLayout1->setSpacing(1);
> vboxLayout1->setMargin(1);
> vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
>
> QMainWindow* window = new QMainWindow(dockWidgetContents);
> window->setObjectName(QString::fromUtf8("window"));
> QWidget* centralwidget = new QWidget(window);
> centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
> QVBoxLayout* vboxLayout = new QVBoxLayout(centralwidget);
> vboxLayout->setSpacing(6);
> vboxLayout->setMargin(9);
> vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
> QTableView* resTableView = new QTableView(centralwidget);
> resTableView->setObjectName(QString::fromUtf8("resTableView"));
>
> vboxLayout->addWidget(resTableView);
>
> window->setCentralWidget(centralwidget);
> QMenuBar* menubar = new QMenuBar(window);
> menubar->setObjectName(QString::fromUtf8("menubar"));
> menubar->setGeometry(QRect(0, 0, 800, 22));
> window->setMenuBar(menubar);
> QStatusBar* statusbar = new QStatusBar(window);
> statusbar->setObjectName(QString::fromUtf8("statusbar"));
> window->setStatusBar(statusbar);
>
> QSize winSize(300, 300);
> winSize = winSize.expandedTo(window->minimumSizeHint());
> window->resize(winSize);
>
> vboxLayout1->addWidget(window);
>
> m_pDockWidget->setWidget(dockWidgetContents);
>
> if (NULL!=parent)
> parent->addDockWidget(static_cast<Qt::DockWidgetArea>(2),
> m_pDockWidget);
>
> m_pDockWidget->setWindowTitle("Test");
>
> m_pDockWidget->setFloating(TRUE);
> QSize size(400, 400);
> m_pDockWidget->resize(size);
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 6 in thread
Pagan Chou wrote:
> Hi Everyone,
> I use QT 4.2.3 as my application GUI toolkit. But I would like
> to create a QMainWindow inside a QDockWidget. Of course,
> this QDockWidget belongs to the top main window of my application.
Just out of interest, why do you need to use a QMainWindow object instead
of, say, a QWidget inside a QDockWidget? What features of QMainWindow do
you need to make available to your dock window?
David
--
[ signature omitted ]
Message 7 in thread
David,
I want to use QMainWindow inside a QDockWidget is for its menu bar and
toolbar.
According to my memory, only QMainWindow can have menu bar and toolbar.
Doesn't it ?
Regards,
Pagan
"David Boddie" <dboddie@xxxxxxxxxxxxx> ???
news:fjuh8b$hln$1@xxxxxxxxxxxxxxxxxx ???...
> Pagan Chou wrote:
>
> > Hi Everyone,
> > I use QT 4.2.3 as my application GUI toolkit. But I would like
> > to create a QMainWindow inside a QDockWidget. Of course,
> > this QDockWidget belongs to the top main window of my application.
>
> Just out of interest, why do you need to use a QMainWindow object instead
> of, say, a QWidget inside a QDockWidget? What features of QMainWindow do
> you need to make available to your dock window?
>
> David
> --
> David Boddie
> Lead Technical Writer, Trolltech ASA
--
[ signature omitted ]
Message 8 in thread
On 18.12.07 14:14:28, Pagan Chou wrote:
> David,
> I want to use QMainWindow inside a QDockWidget is for its menu bar and
> toolbar.
>
> According to my memory, only QMainWindow can have menu bar and toolbar.
> Doesn't it ?
No, you can add a toolbar or menu bar to any QWidget, though it probably
needs some extra code to make the toolbar floatable or moveable. But
adding both of them to a layout works just fine.
Andreas
--
[ signature omitted ]
Message 9 in thread
On Dec 18, 2007 1:14 AM, Pagan Chou <pagan_chou@xxxxxxxxxxxxxx> wrote:
> David,
> I want to use QMainWindow inside a QDockWidget is for its menu bar and
> toolbar.
>
> According to my memory, only QMainWindow can have menu bar and toolbar.
> Doesn't it ?
According to the documentation
(http://doc.trolltech.com/4.3/qmenubar.html) you can construct
menubars and put them in top-level (parent == NULL) widgets. I don't
know if it works on child widgets though (which is what it sounds like
you need to do). It doesn't work on OS X (where there is only the
system menu bar), but Windows or X might let you do it.
--
[ signature omitted ]