How can I get more than the user interface for QMainWindow?

I would like to have a QMainWindow that can change it at runtime, i.e. when the user clicks a button. Besides saving links to different user interface classes created by QtDesigner, is there any other way to do this? Maybe by storing each user interface in a layout? What do you think?

+3
source share
6 answers

I think I got it now.

You have a QMainWindow, and when a certain event is fired, you want to change the appearance of that particular window, for example, remove some buttons, add a tree structure widget or not.

, - , , ++. , Qt Designer.

, , Qt Designer . , Qt Designer, , "ui_classname.h", . , .

, Qt Designer . , - :

MyWindow::MyWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MyWindow)
{
    m_ui->setupUi(this);
}

:

class MyWindow : public QMainWindow {
...
private:
    Ui::MyWindow *m_ui;
};

.

:

class MyWindow : public QMainWindow {
...
private:
    void changeAppearance(int id);

    Ui::MyWindow *m_ui;
    Ui::MyWindowFirstAppearance *m_uiFirst;
    Ui::MyWindowSecondAppearance *m_uiSecond;
...
};

void MyWindow::changeAppearance(int id)
{
     // some code to remove the current appearance, basically the opposite of what setupUi is doing
     if (id == 0)
           m_ui->setupUi(this);
     else...
           m_uiFirst->setupUi(this);
     ...
}

, , Qt Designer, . , , setupUi , , (, setupUi).

+1

? QStackWidget , , . , , . ( , , -, .) , , , .

+5

. Qt QUiLoader.

.

+1

, , . "" , CSS.

, , , .ui , QUiLoader, , , , , .

0

QFrames, QFrames QMainWindow, () () QFrame, ...

0
source

You can use QTabWidgetand hide your buttons. Then you can design each graphical interface in a separate window tabWidget. This has the advantage over hiding frames that you won't clutter up with your Qt Creator window.

0
source

Source: https://habr.com/ru/post/1708318/


All Articles