Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Multiple .ui forms for one class.

    General and Desktop
    4
    7
    4229
    Loading More Posts
    • 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
      sweetMango last edited by

      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)?

      mrjj 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion @sweetMango last edited by mrjj

        @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 Reply Quote 0
        • S
          sweetMango last edited by

          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'

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @sweetMango last edited by

            @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 Reply Quote 1
            • S
              sweetMango last edited by 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.

              jsulm D 2 Replies Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @sweetMango last edited by

                @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 Reply Quote 2
                • D
                  Devopia53 @sweetMango last edited by Devopia53

                  @sweetMango

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

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post