【发布时间】:2010-05-16 11:23:36
【问题描述】:
我是 QT 的绝对初学者..
我正在尝试创建只有文本和一个按钮的窗口,当您按下它时,您将获得另一个具有程序菜单的窗口..
但不幸的是,我不知道如何创建新窗口并将其与主窗口连接!
所以,我需要帮助你
【问题讨论】:
我是 QT 的绝对初学者..
我正在尝试创建只有文本和一个按钮的窗口,当您按下它时,您将获得另一个具有程序菜单的窗口..
但不幸的是,我不知道如何创建新窗口并将其与主窗口连接!
所以,我需要帮助你
【问题讨论】:
这里是一个main.cpp 的示例,正是这样做的(不过您必须修改新窗口)。
#include <QtGui>
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
QWidget *firstWindow = new QWidget();
QLabel *text = new QLabel("Here is some text one the first window.");
QPushButton *button = new QPushButton("Button on the first window that display the other window");
QBoxLayout *layout = new QVBoxLayout();
layout->addWidget(text);
layout->addWidget(button);
firstWindow->setLayout(layout);
QWidget *secondWindow = new QWidget();
// add some things on the second window
// on button click, close the first window and show the second one
connect(button, SIGNAL(clicked(bool)), secondWindow, SLOT(show()));
connect(button, SIGNAL(clicked(bool)), firstWindow, SLOT(close()));
// display the first window at the start of the application.
firstWindow->show();
return app.exec();
}
【讨论】: