【问题标题】:how to create window that opened when close main window?如何创建关闭主窗口时打开的窗口?
【发布时间】:2010-05-16 11:23:36
【问题描述】:

我是 QT 的绝对初学者..

我正在尝试创建只有文本和一个按钮的窗口,当您按下它时,您将获得另一个具有程序菜单的窗口..

但不幸的是,我不知道如何创建新窗口并将其与主窗口连接!

所以,我需要帮助你

【问题讨论】:

    标签: qt qt4 window


    【解决方案1】:

    这里是一个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();
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-29
      • 2018-12-25
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 2013-12-30
      相关资源
      最近更新 更多