Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Do you put everything UI related in mainwindow.cpp?

Do you put everything UI related in mainwindow.cpp?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 6 Posters 246 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mbkerdellou
    wrote last edited by
    #1

    For example in an app where you have multiple pages, say a page for showing the data, a page for showing the settings, a page for chatting, etc.;

    Do you just have a mainwindow.cpp with :

    void createDataView();
    void createSettingsView();
    createChatView();

    or do you create different classes for each and make them inherit QWidget or QGraphicsScene and then have a display(QWidget* page) function thats connected to certain actions that switch the page, and set the page as central view.

    JonBJ 1 Reply Last reply
    0
    • M Mbkerdellou

      For example in an app where you have multiple pages, say a page for showing the data, a page for showing the settings, a page for chatting, etc.;

      Do you just have a mainwindow.cpp with :

      void createDataView();
      void createSettingsView();
      createChatView();

      or do you create different classes for each and make them inherit QWidget or QGraphicsScene and then have a display(QWidget* page) function thats connected to certain actions that switch the page, and set the page as central view.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by JonB
      #2

      @Mbkerdellou
      You certainly create separate classes/files for each "item" or "page" which is a widget, of whatever kind. You can use Designer to design them as .ui files with corresponding class files if you wish. You may create them from the main window but they are their own widgets.

      As for showing them one at a time, there are many ways. You can show and hide widgets. If you want to have a QMainWindow with a single central widget which changes, you can use QStackedWidget: you put each of your widgets as a "page" and it only displays one at a time, under your control.

      1 Reply Last reply
      4
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote last edited by Kent-Dorfman
        #3

        logically that is entirely up to you, but no, I don't. I try to follow an OO approach that closely models what I'm trying to accomplish.

        The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

        1 Reply Last reply
        3
        • M Offline
          M Offline
          Mbkerdellou
          wrote last edited by
          #4

          thank you @JonB and @Kent-Dorfman

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote last edited by
            #5

            Hi,

            In addition to my fellows, never use a god like class that does everything. You're in for maintenance hell.

            Split your UI in logical pieces. That will allow to also test them independently.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3
            • Joe von HabsburgJ Offline
              Joe von HabsburgJ Offline
              Joe von Habsburg
              wrote last edited by
              #6

              @JonB said in Do you put everything UI related in mainwindow.cpp?:

              you can use QStackedWidget:

              @SGaist said in Do you put everything UI related in mainwindow.cpp?:

              Split your UI in logical pieces

              Theese are true options, If you want to open different window, you use create new class. Stacked or Tab widgets are good.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leo daas
                Banned
                wrote last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved