[Qt-interest] QMainWindow and QDialog.
Andreas Diehl
Andreas_Diehl at abs.org
Thu Mar 26 14:30:32 CET 2009
Hello.
For a QMainWindow you have to set the central widget. Try adding
QWidget* centralWidget = new QWidget();
centralWidget->setLayout(mainLayout));
this->setCentralWidget(centralWidget);
instead of your "setLayout(mainLayout)" line.
A QMainWindow has a special central area for "normal" layouting. The surroundings are for QDockWidgets and QToolbars. Look at the QMainWindow reference, there's a picture explaining it.
Regards,
Andreas
________________________________
Von: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] Im Auftrag von Shabd Swarup V
Gesendet: Donnerstag, 26. März 2009 14:07
An: qt-interest at trolltech.com
Betreff: [Qt-interest] QMainWindow and QDialog.
Hi,
I have a class called Window which inherits from QMainWindow. Following is its constructor:
Window::Window(QWidget *parent)
: QMainWindow(parent)
{
tableWidget = new QTableWidget();
treeWidget = new QTreeWidget();
details = new QTextEdit("Gambler Details");
addButton = createButton(tr("&Add"), SLOT(add()));
editButton = createButton(tr("&Edit"), SLOT(edit()));
graphicsView = new QGraphicsView();
deleteButton = new QPushButton("Delete");
QLabel *filterLabel = new QLabel("Filter Gambler");
QHBoxLayout *radioLayout = new QHBoxLayout;
radioLayout->addWidget(filterLabel);
QVBoxLayout *buttonsLayout = new QVBoxLayout;
buttonsLayout->addStretch();
buttonsLayout->addWidget(addButton, Qt::AlignVCenter);
buttonsLayout->addWidget(editButton, Qt::AlignVCenter);
buttonsLayout->addWidget(deleteButton, Qt::AlignVCenter);
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(graphicsView, 0, 0, 1, 3);
mainLayout->addWidget(treeWidget, 1, 0,3,1);
mainLayout->addLayout(radioLayout, 1, 1,1,1);
mainLayout->addWidget(tableWidget, 2, 1, 1, 1);
mainLayout->addWidget(details, 3, 1, 1, 2);
mainLayout->addLayout(buttonsLayout, 2, 2, 1, 1);
setLayout(mainLayout);
setWindowTitle(tr("Gambler"));
resize(800, 700);
}
This displays a completely blank window. Although, if I make Window inherit from QDialog instead of QMainWindow, the widgets are displayed perfectly fine.
Please suggest how I can make this work while keeping the base class as QMainWindow.
Thanks,
Shabd
PS: This is my first Qt GUI app.
--
Mit freundlichen Grüßen
Andreas Diehl
-------------------------- ABS -------------------------
ABS Systemberatung OHG Tel: +49 (0)7053/9290-03
Hauffstr. 9 Fax: +49 (0)7053/9290-
D-75385 Bad Teinach-Zavelstein http://www.abs.org
Registergericht Calw HRA 1031
[mailto:Andreas_Diehl at abs.org]
----- Loesungen fuer den Maschinen- und Anlagenbau -----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090326/74fcf9eb/attachment.html
More information about the Qt-interest-old
mailing list