从窗口打开新窗口QT? [英] opening new window from a window QT?

查看:185
本文介绍了从窗口打开新窗口QT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个类都定义在QDialog类下。

I have two classes both define under QDialog class.

两个类都单独工作正常,并打开各自的窗口,但我想要的是从一个窗口在菜单中的一个动作,其中点击打开另一个窗口。
所定义类的代码为
class 1

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

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

class Box1 : public QDialog
{
        Q_OBJECT

        public:
                Box1(QWidget *parent=0);

        private:
                QLineEdit *text;
                QLabel *searchh;
                QDialogButtonBox *buttonboxx;
                QTableView *tablee;
                QGroupBox *tableegroup;
                QGroupBox *searchgroup;
};

操作将在Box中打开Box1。
_ 我还有图像,我已经创建并试图上传,但它说我需要10个声誉,这样做,所以我不能这样做。 p>

The action will be there in Box which will open 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.

推荐答案

我不明白。如果我理解这个问题,你只需要连接QAction从您的QMenuBar到功能,这将对应创建新的窗口与Box1小部件。这里你是如何做的简单例子:

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. 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();
}

connect(Box1Action, SIGNAL(triggered()), this, SLOT(newDialog()));

或更简单:

myMenu->addAction(tr("Create Box1 Window"), this, SLOT(newDialog()));

这篇关于从窗口打开新窗口QT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆