Reputation: 4333
I have QMainWindow
, and QWidget
like :
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_actionUserAdd_triggered();
void on_actionEditUser_triggered();
void on_actionShow_User_triggered();
private:
Ui::MainWindow *ui;
EditUser *editUserWindow;
ShowUser *showUserWindow;
};
QWidget is :
namespace Ui {
class EditUser;
}
class EditUser : public QWidget
{
Q_OBJECT
public:
explicit EditUser(QWidget *parent = 0);
~EditUser();
private:
Ui::EditUser *ui;
};
And when actionEditUser is triggered I am creating new form:
editUserWindow = new EditUser();
editUserWindow->show();
However I do not want to open/create new form. I want to paste QWidget(EditUser) to QMainWindow
. So that appliction can work on just 1 form, instead of 2,3 or more. Could you please kindly help me how to do it?
Upvotes: 1
Views: 508
Reputation: 18504
In Qt
widget without parent is a separate window. So answer is simple: just set parent. For example:
editUserWindow = new EditUser(this);//inside mainwindow, mainwinodw is a parent of EditUser
editUserWindow->show();
But in this case editUserWindow
will be placed at 0,0
position(in parent coordinates)(top left) , so you have 2 approaches. Use setGeometry()
to set x
,y
, width
and height
of widget, and better approach: add this widget to your current layout.
Upvotes: 2