[英]opening new window from a window QT?
I have two classes both define under QDialog class. 我有两个类都在QDialog类下定义。
Both classes individually are working properly and opening their respective window but what i want is that from one window there is an action in the menubar ,which on clicking open the other window. 两个类单独工作正常并打开它们各自的窗口,但我想要的是从一个窗口在菜单栏中有一个动作,点击打开另一个窗口。 codes for the classes defined are class 1
定义的类的代码是1类
class Box : public QDialog
{
Q_OBJECT
public:
Box(QWidget *parent=0);
private slots:
void refresh();
signals:
void itemChanged(QStandardItem *);
private:
void create_frame();
void create_menu();
QGroupBox *tablegroup;
QDialogButtonBox *buttonbox;
QAction *help;
QAction *exit;
QAction *idseacrh;
QAction *idsearch;
QMenu *file;
QMenu *search;
QMenuBar *menubar;
QTableView *table;
};
CLASS 2 2级
class Box1 : public QDialog
{
Q_OBJECT
public:
Box1(QWidget *parent=0);
private:
QLineEdit *text;
QLabel *searchh;
QDialogButtonBox *buttonboxx;
QTableView *tablee;
QGroupBox *tableegroup;
QGroupBox *searchgroup;
};
The action will be there in Box which will open Box1. 行动将在Box中打开,它将打开Box1。 _ I HAVE IMAGE ALSO FOR BOTH THE _ window which i have created and tried to upload but it says i need 10 reputations to do this,so i wasnt able to do it.
_ 我的图像也是我创建并试图上传的_窗口,但它说我需要10个声誉才能做到这一点,所以我无法做到这一点。
I don't get it. 我不明白。 If i understood the question, you just need to connect QAction from your QMenuBar to function which will correspond for creating new window with Box1 widget.
如果我理解了这个问题,你只需要将QAction从QMenuBar连接到与Box1小部件创建新窗口相对应的功能。 Here you are simple example of how to do it:
在这里,您是如何做到这一点的简单示例:
void Box::newDialog()
{
QVBoxLayout* lay = new QVBoxLayout;
Box1* temp = new Box1(this);
lay->addWidget(temp);
QDialog dialog(this);
dialog.setModal(true);
dialog.setLayout(lay);
dialog.setWindowTitle("Box1");
dialog.exec();
}
And 和
connect(Box1Action, SIGNAL(triggered()), this, SLOT(newDialog()));
or simpler: 或者更简单:
myMenu->addAction(tr("Create Box1 Window"), this, SLOT(newDialog()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.