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. stackedwidget for different class which they have their own .cpp , .h, and .ui

stackedwidget for different class which they have their own .cpp , .h, and .ui

Scheduled Pinned Locked Moved General and Desktop
16 Posts 3 Posters 4.5k 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
    marlenet15
    wrote on last edited by
    #5

    The thing is there were going to be multiple pages and I wanted to stack the widgets in a different file. I was able to achieve that with Page_stackedWidget.ui. However, I would like it so when I press a button that is in page 1 it takes me to page 2. This is what I have for Page_stackedWidget.cpp

    #include "dialog.h"
    #include "ui_dialog.h"
    
    Page_stackedWidget::Page_stackedWidget(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    }
    ui->setupUi(this);
    connect(_signin->nextButton, SIGNAL(clicked()),this,SLOT(goToPage2())); 
    }
    
    void Dialog::goToPage2()
    {
    ui->stackedWidget->setCurrentIndex(1);
    }
    

    However, the "nextButton" I created on the .ui file for Page1. I have looked for forums and i have found some similar to my problem but the difference is that their button is created on this file. http://stackoverflow.com/questions/9694474/manipulating-qt-ui-with-different-source-files.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Hi
      If I understand you correctly,
      you can maybe use the promote feature.

      Say you have
      UI A,B,C
      B and C contains widgets like buttons etc.

      on A you put a stacked widget
      and on page 1 it has all of B, and on page 2, it has all of C
      and they still live in their own UI files. ?

      That you can do via promote. In short you place a QWidget in the stacked paged and it will be replaced
      by all widget from an UI file. When you run the program.
      Note: select QWidget as parent, not dialog when you create B,C.

      Please see
      https://forum.qt.io/topic/59373/solved-recommended-approach-for-inline-modal/13

      If its not what you mean, then sorry :)

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        If I understand you correctly,
        you can maybe use the promote feature.

        Say you have
        UI A,B,C
        B and C contains widgets like buttons etc.

        on A you put a stacked widget
        and on page 1 it has all of B, and on page 2, it has all of C
        and they still live in their own UI files. ?

        That you can do via promote. In short you place a QWidget in the stacked paged and it will be replaced
        by all widget from an UI file. When you run the program.
        Note: select QWidget as parent, not dialog when you create B,C.

        Please see
        https://forum.qt.io/topic/59373/solved-recommended-approach-for-inline-modal/13

        If its not what you mean, then sorry :)

        M Offline
        M Offline
        marlenet15
        wrote on last edited by
        #7

        @mrjj I did put a widget on the stackedWidget. Even though it is a QDialog, I created a widget inside of it. I was able to call the files and add them into the stackwidget. My question now is how do I call a qpushbutton created from Page1?

        mrjjM 1 Reply Last reply
        0
        • M marlenet15

          @mrjj I did put a widget on the stackedWidget. Even though it is a QDialog, I created a widget inside of it. I was able to call the files and add them into the stackwidget. My question now is how do I call a qpushbutton created from Page1?

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

          @marlenet15
          well , say the place holder widget is called Wid2, (the one you promoted)
          then you can access any widget using the normal

          ui->Wid2->SomeButton

          its being created in the ui_xx file for the UI that contains the promoted widgets.

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

            Each widget should be self-contained so what exactly do you want to do with that button from another widget in your stack ?

            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
            0
            • M Offline
              M Offline
              marlenet15
              wrote on last edited by
              #10

              I want to press that button to go the next page that is in the stack

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

                In that case and from a design point of view, does it really belong to a widget inside the stack ?

                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
                0
                • M Offline
                  M Offline
                  marlenet15
                  wrote on last edited by
                  #12

                  Yes it does.

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

                    Then add a signal to that widget that will forward the button clicked signal. Something like nextPageRequested. That will be cleaner and easier to understand when you read the code.

                    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
                    0
                    • M Offline
                      M Offline
                      marlenet15
                      wrote on last edited by
                      #14

                      I know but how am I supposed to access that widget when it is in another class?

                      connect(Page1->nextButton, SIGNAL(clicked()),this,SLOT(goToPage2()));
                      

                      Where Page1 is the widget that contains the button "nextButton" and when you press it will go to Page2

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

                        That's what I wrote: you don't access the button, you only connect Page1.

                        Are you trying to re-implement QWizard ?

                        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
                        0
                        • M Offline
                          M Offline
                          marlenet15
                          wrote on last edited by
                          #16

                          Yes but I do not want to use QWizard since I don't want it in that style. The only similarity is that I can go from one page to another.

                          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