[英]QT Designer: opening specific window on action
I'm new to QT Designer and would like to open a specific window from an action. 我是QT Designer的新手,并且想从操作中打开特定的窗口。 I've searched and all the examples I've seen are like this answer and only give a generic new window, not one that's already predefined.
我进行了搜索,看到的所有示例都类似于此答案,并且仅提供了一个通用的新窗口,而不是已经预定义的窗口。 Right now I'm trying to open a predefined window (with header, source, and form) called listcsv right after the file dialog is fulfilled.
现在,我正在尝试在完成文件对话框后立即打开一个名为listcsv的预定义窗口(包含标题,源代码和表单)。 But the code just makes a generic blank window pop up, not the one I need.
但是代码只是弹出一个通用的空白窗口,而不是我需要的那个窗口。
Here's my main window .cpp: 这是我的主窗口.cpp:
#include "csv_helper.h"
#include "ui_csv_helper.h"
#include "listcsv.h"
#include "ui_listcsv.h"
#include <QFileDialog>
#include <QWindow>
CSV_helper::CSV_helper(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::CSV_helper)
{
ui->setupUi(this);
}
CSV_helper::~CSV_helper()
{
delete ui;
}
void CSV_helper::on_buttonBox_accepted()
{
QFileDialog::getOpenFileName(this, tr("Open CSV"), "/Users/Dropbox", tr("CSV Files (*.csv)"));
QWidget *listcsv = new QWidget;
listcsv->show();
hide();
}
I feel frustrated that this is over something so simple, but nothing on the internet seems to give a straight answer. 我对这太简单了,感到很沮丧,但是互联网上似乎没有一个直接的答案。
Edit: Solved, thanks to john elemans. 编辑:解决了,感谢约翰·埃勒曼斯。 Just had to modify some things.
只是不得不修改一些东西。
void CSV_helper::on_buttonBox_accepted()
{
QFileDialog::getOpenFileName(this, tr("Open CSV"), "/Users/Dropbox", tr("CSV Files (*.csv)"));
ListCSV *msd;
msd = new ListCSV();
msd->show();
}
Define your new window's layout in a form file with name to match your dialog. 在表单文件中定义新窗口的布局,其名称要与对话框匹配。 Create a new C++ class with a base type of QDialog, called, for example, mySpecialDialog.
创建一个新的C ++类,其基本类型为QDialog,例如,称为mySpecialDialog。 It should refer the form file as follows;
它应按如下方式引用表单文件; Private: UI::mySpecialDialog ui;
私有:UI :: mySpecialDialog ui;
Then in your main code, when you want the dialog,... 然后在主代码中,当您需要对话框时,...
mySpecialDialog *msd;
msd = new mySpecialDialog();
if (msd->exec() == QDialog::Accepted)
{
... code
}
else
{
}
voila. 瞧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.