Reputation: 145
I have two classes both define under QDialog class.
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;
};
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.
Upvotes: 0
Views: 2520
Reputation: 4186
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();
}
And
connect(Box1Action, SIGNAL(triggered()), this, SLOT(newDialog()));
or simpler:
myMenu->addAction(tr("Create Box1 Window"), this, SLOT(newDialog()));
Upvotes: 2