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. Multiple .ui forms for one class.
Forum Update on Monday, May 27th 2025

Multiple .ui forms for one class.

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 5.4k Views
  • 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.
  • S Offline
    S Offline
    sweetMango
    wrote on last edited by
    #1

    Hi!

    I have an class, that adds new filter to list. I want to transform the window, so it only give to user ability to edit color of filter. I have a form prepared. Is there any option to link two forms to one class, and setup it by ui->setupUI, depending on option triggered by user (Add/Edit)?

    mrjjM 1 Reply Last reply
    0
    • S sweetMango

      Hi!

      I have an class, that adds new filter to list. I want to transform the window, so it only give to user ability to edit color of filter. I have a form prepared. Is there any option to link two forms to one class, and setup it by ui->setupUI, depending on option triggered by user (Add/Edit)?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @sweetMango
      Well you can use
      http://doc.qt.io/qt-5/quiloader.html
      to load an UI file at runtime.

      You can also use setupUI() but that depends on the ui_widgetname file as its a class with variables in
      so not sure what you want to do.

      You want to replace all widgets in a from with the widgets defines in others forms setup?

      You can do
      Ui::SomeName * ui2 = new Ui::SomeName;
      ui2->setup(this)
      To create all widgets defines in SomeName form with other widget as parent.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sweetMango
        wrote on last edited by
        #3

        Actually I want to change window connected to the class, but keep this class methods and functionality. For eg.

        I have this view:
        0_1533625126807_1.png

        And I want to transform it to this:
        1_1533625126807_2.png

        Linking new Ui like: Ui::SomeName * ui2 = new Ui::SomeName; says : error: allocation of incomplete type 'Ui::EditColorWindow'

        jsulmJ 1 Reply Last reply
        0
        • S sweetMango

          Actually I want to change window connected to the class, but keep this class methods and functionality. For eg.

          I have this view:
          0_1533625126807_1.png

          And I want to transform it to this:
          1_1533625126807_2.png

          Linking new Ui like: Ui::SomeName * ui2 = new Ui::SomeName; says : error: allocation of incomplete type 'Ui::EditColorWindow'

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @sweetMango Why don't you simply create two different widgets with designer and then put the one you currently need in your dialog? You could even use http://doc.qt.io/qt-5/qstackedwidget.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • S Offline
            S Offline
            sweetMango
            wrote on last edited by sweetMango
            #5

            @jsulm This is what I want to do, but I'm not really sure how to do this. Stacking widgets looks a lil' bit too "overcomplicated".

            I thought about something like this:

            AddFilter::AddFilter(QWidget* parent, bool flag) :
                QDialog(parent),
                ui(new Ui::AddFilter)
            {
            if (flag){
                ui->setupUi(this);
                setFixedSize(471, 421);
            }
            else{
                Ui::EditColorWindow *ui2 = new Ui::EditColorWindow;
                ui2->setupUi(this);
            }
            

            but it gives me error mentioned earlier.

            jsulmJ D 2 Replies Last reply
            0
            • S sweetMango

              @jsulm This is what I want to do, but I'm not really sure how to do this. Stacking widgets looks a lil' bit too "overcomplicated".

              I thought about something like this:

              AddFilter::AddFilter(QWidget* parent, bool flag) :
                  QDialog(parent),
                  ui(new Ui::AddFilter)
              {
              if (flag){
                  ui->setupUi(this);
                  setFixedSize(471, 421);
              }
              else{
                  Ui::EditColorWindow *ui2 = new Ui::EditColorWindow;
                  ui2->setupUi(this);
              }
              

              but it gives me error mentioned earlier.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @sweetMango What you're trying with UI files is overcomplicated.
              There is nothing complicated with stacked widgets.
              But if you don't want to use them then take a look at http://doc.qt.io/qtcreator/creator-writing-program.html
              You simply need to create two widgets, then create and show the one you currently need.
              Sounds complicated? Use stacked widgets, should be simpler.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • S sweetMango

                @jsulm This is what I want to do, but I'm not really sure how to do this. Stacking widgets looks a lil' bit too "overcomplicated".

                I thought about something like this:

                AddFilter::AddFilter(QWidget* parent, bool flag) :
                    QDialog(parent),
                    ui(new Ui::AddFilter)
                {
                if (flag){
                    ui->setupUi(this);
                    setFixedSize(471, 421);
                }
                else{
                    Ui::EditColorWindow *ui2 = new Ui::EditColorWindow;
                    ui2->setupUi(this);
                }
                

                but it gives me error mentioned earlier.

                D Offline
                D Offline
                Devopia53
                wrote on last edited by Devopia53
                #7

                @sweetMango

                Append header: #include "ui_editcolorwindow.h in .cpp.

                1 Reply Last reply
                1
                • Pl45m4P Pl45m4 referenced this topic on

                • Login

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