Shrikant Singh Shrikant Singh - 1 year ago 103
C++ Question

Is it possible to switch between two UI form in one class in qt?

I have following two classes with their UI forms.

  1. loginWindow

  2. mainWindow

Now when I need to go to the mainWindow I click on the push button in loginWindow and a new window pops up that is the mainWindow.

void LoginWindow::on_pbLogin_clicked()
MainWindow *mainW = new MainWindow;

What I am trying to have is to get the contents of mainWindow in the loginWindow.
I could switch/move to mainWindow from LoginWindow in the same window, without mainWindow creating its own window to show its content and I don't want to use qstackedwidget

Is it possible? if yes, how can I achieve this?

Answer Source

If we assume that LoginWindow and MainWindow are both derived from QMainWindow (otherwise it wouldn't just be a content switch), then one option other than using a QStackedWidget would be to have the two form classes derive from QWidget and use either as the centralWidget of a single QMainWindow instance.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download