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. Syntax for Vector of QPushbuttons added to FlowLayout
QtWS25 Last Chance

Syntax for Vector of QPushbuttons added to FlowLayout

Scheduled Pinned Locked Moved Solved General and Desktop
52 Posts 6 Posters 4.6k 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.
  • J JKSH
    14 Dec 2021, 05:09

    @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

    scrollArea operation does not seem to be working.

    You need to add some code that puts scrollArea into this.

    S Offline
    S Offline
    Swati777999
    wrote on 14 Dec 2021, 07:03 last edited by Swati777999
    #10

    @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:

    @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

    scrollArea operation does not seem to be working.

    You need to add some code that puts scrollArea into this.

    Do you mean that I should write QScrollArea *scrollArea= new QScrollArea(this);

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    1 Reply Last reply
    0
    • J JKSH
      14 Dec 2021, 05:09

      @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

      scrollArea operation does not seem to be working.

      You need to add some code that puts scrollArea into this.

      S Offline
      S Offline
      Swati777999
      wrote on 14 Dec 2021, 07:48 last edited by Swati777999
      #11

      @JKSH
      FlowLayoutDiag.PNG

      This is the diagram of the parent-child items of the above code [expected output in the window]

      So, you mean I should write
      QScrollArea *scrollArea = new QScrollArea(parentWidget);
      My program produces buttons in a vertical layout with deactivated scrollbar functionality.

      “ In order to be irreplaceable, one must always be different” – Coco Chanel

      J 1 Reply Last reply 14 Dec 2021, 08:26
      0
      • S Swati777999
        14 Dec 2021, 07:48

        @JKSH
        FlowLayoutDiag.PNG

        This is the diagram of the parent-child items of the above code [expected output in the window]

        So, you mean I should write
        QScrollArea *scrollArea = new QScrollArea(parentWidget);
        My program produces buttons in a vertical layout with deactivated scrollbar functionality.

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 14 Dec 2021, 08:26 last edited by JKSH
        #12

        @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

        So, you mean I should write
        QScrollArea *scrollArea = new QScrollArea(parentWidget);

        According to your diagram,

        • You should add the QPushButtons to flowLayout
        • You should add flowLayout to ChildWidget
        • You should add ChildWidget to ParentLayout
        • You should add ParentLayout to ParentWidget

        Can you point out to us: Which part of your code achieves each step?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        S 1 Reply Last reply 14 Dec 2021, 09:16
        1
        • J JKSH
          14 Dec 2021, 08:26

          @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

          So, you mean I should write
          QScrollArea *scrollArea = new QScrollArea(parentWidget);

          According to your diagram,

          • You should add the QPushButtons to flowLayout
          • You should add flowLayout to ChildWidget
          • You should add ChildWidget to ParentLayout
          • You should add ParentLayout to ParentWidget

          Can you point out to us: Which part of your code achieves each step?

          S Offline
          S Offline
          Swati777999
          wrote on 14 Dec 2021, 09:16 last edited by
          #13

          @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
          Find my answers below:
          You should add the QPushButtons to flowLayout -
          flowLayout->addWidget(pb); //inside the for loop

          You should add flowLayout to ChildWidget
          childWidget->setLayout(flowLayout); // Inside the for loop

          You should add ChildWidget to ParentLayout
          Missed this one in the above code but now I have included the following in my code
          parentLayout->addWidget(childWidget); //Adding childWidget to parent layout
          After including this code, I am not getting the result. :(

          You should add ParentLayout to ParentWidget
          parentWidget->setLayout(parentLayout);

          “ In order to be irreplaceable, one must always be different” – Coco Chanel

          J 1 Reply Last reply 14 Dec 2021, 11:40
          0
          • S Swati777999
            14 Dec 2021, 09:16

            @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
            Find my answers below:
            You should add the QPushButtons to flowLayout -
            flowLayout->addWidget(pb); //inside the for loop

            You should add flowLayout to ChildWidget
            childWidget->setLayout(flowLayout); // Inside the for loop

            You should add ChildWidget to ParentLayout
            Missed this one in the above code but now I have included the following in my code
            parentLayout->addWidget(childWidget); //Adding childWidget to parent layout
            After including this code, I am not getting the result. :(

            You should add ParentLayout to ParentWidget
            parentWidget->setLayout(parentLayout);

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 14 Dec 2021, 11:40 last edited by JKSH
            #14

            @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

            You should add the QPushButtons to flowLayout -
            flowLayout->addWidget(pb); //inside the for loop

            You should add flowLayout to ChildWidget
            childWidget->setLayout(flowLayout); // Inside the for loop

            You should add ChildWidget to ParentLayout
            Missed this one in the above code but now I have included the following in my code
            parentLayout->addWidget(childWidget); //Adding childWidget to parent layout
            After including this code, I am not getting the result. :(

            You should add ParentLayout to ParentWidget
            parentWidget->setLayout(parentLayout);

            Yep, these are all good. Next:

            1. Where does QScrollArea fit in your widget hierarchy? (Remember that QScrollArea is a widget)
            2. Why do you call childWidget->setLayout(flowLayout); multiple times?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            S 1 Reply Last reply 15 Dec 2021, 01:36
            1
            • J JKSH
              14 Dec 2021, 11:40

              @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

              You should add the QPushButtons to flowLayout -
              flowLayout->addWidget(pb); //inside the for loop

              You should add flowLayout to ChildWidget
              childWidget->setLayout(flowLayout); // Inside the for loop

              You should add ChildWidget to ParentLayout
              Missed this one in the above code but now I have included the following in my code
              parentLayout->addWidget(childWidget); //Adding childWidget to parent layout
              After including this code, I am not getting the result. :(

              You should add ParentLayout to ParentWidget
              parentWidget->setLayout(parentLayout);

              Yep, these are all good. Next:

              1. Where does QScrollArea fit in your widget hierarchy? (Remember that QScrollArea is a widget)
              2. Why do you call childWidget->setLayout(flowLayout); multiple times?
              S Offline
              S Offline
              Swati777999
              wrote on 15 Dec 2021, 01:36 last edited by
              #15

              @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:

              1. Where does QScrollArea fit in your widget hierarchy? (Remember that QScrollArea is a widget)
              flowLayout ->addWidget(scrollArea); flowLayout is the child Layout.

              2. Why do you call childWidget->setLayout(flowLayout); multiple times?
              It's by mistake I wrote it. childWidget is the widget for flowLayout. Refer the following code.

                  {   int n=20;
                  QWidget *parentWidget =new QWidget(this);
                  QGridLayout *parentLayout =new QGridLayout(parentWidget);
                  parentWidget->setLayout(parentLayout);
              
                  FlowLayout *flowLayout = new FlowLayout();
                  parentLayout->addLayout(flowLayout,1,0);  //Adding child layout to parentlayout
              
              
                  QWidget *childWidget = new QWidget(); //Child Widget for flowLayout
                  parentLayout->addWidget(childWidget); //Adding childWidget to parent layout
              
              
                  QVector <QPushButton *> buttons(n);
                  QScrollArea *scrollArea = new QScrollArea(parentWidget);
                  flowLayout ->addWidget(scrollArea);
              
              
                  for (int ii=0;ii<n;ii++)
                  {
                      QPushButton * pb = new QPushButton(); // creating buttons
                         pb->setMinimumSize(200,200);
                         buttons.push_back(pb); // adding buttons to qvector
                         flowLayout->addWidget(pb);
                   }
              
                  childWidget->setLayout(flowLayout);  //setting Layout for the childWidget
              
                  scrollArea->setWidget(childWidget);
                  scrollArea->widget()->setEnabled(true);
                
                this->show();
              }
              

              I get the following result after making the change. I don't know what the first box is.

              flowLayout_scroll_pushbuttons_15.12.PNG

              “ In order to be irreplaceable, one must always be different” – Coco Chanel

              J 1 Reply Last reply 15 Dec 2021, 04:33
              0
              • S Swati777999
                15 Dec 2021, 01:36

                @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:

                1. Where does QScrollArea fit in your widget hierarchy? (Remember that QScrollArea is a widget)
                flowLayout ->addWidget(scrollArea); flowLayout is the child Layout.

                2. Why do you call childWidget->setLayout(flowLayout); multiple times?
                It's by mistake I wrote it. childWidget is the widget for flowLayout. Refer the following code.

                    {   int n=20;
                    QWidget *parentWidget =new QWidget(this);
                    QGridLayout *parentLayout =new QGridLayout(parentWidget);
                    parentWidget->setLayout(parentLayout);
                
                    FlowLayout *flowLayout = new FlowLayout();
                    parentLayout->addLayout(flowLayout,1,0);  //Adding child layout to parentlayout
                
                
                    QWidget *childWidget = new QWidget(); //Child Widget for flowLayout
                    parentLayout->addWidget(childWidget); //Adding childWidget to parent layout
                
                
                    QVector <QPushButton *> buttons(n);
                    QScrollArea *scrollArea = new QScrollArea(parentWidget);
                    flowLayout ->addWidget(scrollArea);
                
                
                    for (int ii=0;ii<n;ii++)
                    {
                        QPushButton * pb = new QPushButton(); // creating buttons
                           pb->setMinimumSize(200,200);
                           buttons.push_back(pb); // adding buttons to qvector
                           flowLayout->addWidget(pb);
                     }
                
                    childWidget->setLayout(flowLayout);  //setting Layout for the childWidget
                
                    scrollArea->setWidget(childWidget);
                    scrollArea->widget()->setEnabled(true);
                  
                  this->show();
                }
                

                I get the following result after making the change. I don't know what the first box is.

                flowLayout_scroll_pushbuttons_15.12.PNG

                J Offline
                J Offline
                JKSH
                Moderators
                wrote on 15 Dec 2021, 04:33 last edited by
                #16

                @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                1. Where does QScrollArea fit in your widget hierarchy? (Remember that QScrollArea is a widget)
                flowLayout ->addWidget(scrollArea); flowLayout is the child Layout.

                Your code puts things in this order:

                1. scrollArea inside flowLayout
                2. flowLayout inside childWidget
                3. childWidget inside scrollArea

                So which of these objects is meant to be the one "outside"?

                I suggest you update your diagram and include QScrollArea in the diagram.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                S 1 Reply Last reply 15 Dec 2021, 04:46
                1
                • J JKSH
                  15 Dec 2021, 04:33

                  @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                  1. Where does QScrollArea fit in your widget hierarchy? (Remember that QScrollArea is a widget)
                  flowLayout ->addWidget(scrollArea); flowLayout is the child Layout.

                  Your code puts things in this order:

                  1. scrollArea inside flowLayout
                  2. flowLayout inside childWidget
                  3. childWidget inside scrollArea

                  So which of these objects is meant to be the one "outside"?

                  I suggest you update your diagram and include QScrollArea in the diagram.

                  S Offline
                  S Offline
                  Swati777999
                  wrote on 15 Dec 2021, 04:46 last edited by
                  #17

                  @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:

                  So which of these objects is meant to be the one "outside"?
                  I suggest you update your diagram and include QScrollArea in the diagram.

                  Here's the updated diagram for scrollArea, notice that the scrollArea Widget is in pink color.
                  FlowLayoutDiag_scroll.PNG

                  “ In order to be irreplaceable, one must always be different” – Coco Chanel

                  J 1 Reply Last reply 15 Dec 2021, 05:19
                  0
                  • S Swati777999
                    15 Dec 2021, 04:46

                    @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:

                    So which of these objects is meant to be the one "outside"?
                    I suggest you update your diagram and include QScrollArea in the diagram.

                    Here's the updated diagram for scrollArea, notice that the scrollArea Widget is in pink color.
                    FlowLayoutDiag_scroll.PNG

                    J Offline
                    J Offline
                    JKSH
                    Moderators
                    wrote on 15 Dec 2021, 05:19 last edited by
                    #18

                    @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                    Here's the updated diagram for scrollArea, notice that the scrollArea Widget is in pink color.

                    • According to your diagram, scrollArea is inside childWidget
                    • According to your code, childWidget is inside scrollArea.

                    Which one is correct?

                    Notes:

                    • I said this before: QScrollArea is a QWidget. You can't put a QScrollArea between your FlowLayout and your buttons.
                    • In case it's not obvious: QPushButton is also a QWidget.
                    • Your design is extremely complicated. I suggest you reduce the number of widgets and layouts.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    S 1 Reply Last reply 15 Dec 2021, 06:10
                    2
                    • J JKSH
                      15 Dec 2021, 05:19

                      @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                      Here's the updated diagram for scrollArea, notice that the scrollArea Widget is in pink color.

                      • According to your diagram, scrollArea is inside childWidget
                      • According to your code, childWidget is inside scrollArea.

                      Which one is correct?

                      Notes:

                      • I said this before: QScrollArea is a QWidget. You can't put a QScrollArea between your FlowLayout and your buttons.
                      • In case it's not obvious: QPushButton is also a QWidget.
                      • Your design is extremely complicated. I suggest you reduce the number of widgets and layouts.
                      S Offline
                      S Offline
                      Swati777999
                      wrote on 15 Dec 2021, 06:10 last edited by
                      #19

                      @JKSH

                      I want to set the scrolling functionality for the array of pushbuttons. That's the reason why I put scrollArea inside the flowLayout.

                      “ In order to be irreplaceable, one must always be different” – Coco Chanel

                      P J 2 Replies Last reply 15 Dec 2021, 14:27
                      0
                      • S Swati777999
                        15 Dec 2021, 06:10

                        @JKSH

                        I want to set the scrolling functionality for the array of pushbuttons. That's the reason why I put scrollArea inside the flowLayout.

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 15 Dec 2021, 14:27 last edited by
                        #20

                        @Swati777999

                        And where do you want to have your flowLayout?
                        Your design is really confusing.

                        How about putting a widget with a flowLayout containing your buttons in your ScrollArea?!
                        Still don't know if that is what you are trying to achieve.
                        From you figure, it looks like you have a least 1 or 2 (parent) widgets and layouts more than necessarily needed.


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        S 1 Reply Last reply 17 Dec 2021, 01:27
                        1
                        • S Swati777999
                          15 Dec 2021, 06:10

                          @JKSH

                          I want to set the scrolling functionality for the array of pushbuttons. That's the reason why I put scrollArea inside the flowLayout.

                          J Offline
                          J Offline
                          JKSH
                          Moderators
                          wrote on 16 Dec 2021, 12:23 last edited by JKSH
                          #21

                          @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                          I want to set the scrolling functionality for the array of pushbuttons. That's the reason why I put scrollArea inside the flowLayout.

                          Then you should:

                          1. Put the flowLayout in a container/child widget
                          2. Put that container/child widget in the scrollArea

                          But before that, simplify your design and remove the widgets and layouts that you don't need. Both myself and @Pl45m4 have asked you to do this. Please don't ignore our words.

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          S 1 Reply Last reply 17 Dec 2021, 01:46
                          4
                          • P Pl45m4
                            15 Dec 2021, 14:27

                            @Swati777999

                            And where do you want to have your flowLayout?
                            Your design is really confusing.

                            How about putting a widget with a flowLayout containing your buttons in your ScrollArea?!
                            Still don't know if that is what you are trying to achieve.
                            From you figure, it looks like you have a least 1 or 2 (parent) widgets and layouts more than necessarily needed.

                            S Offline
                            S Offline
                            Swati777999
                            wrote on 17 Dec 2021, 01:27 last edited by Swati777999
                            #22

                            @Pl45m4 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                            How about putting a widget with a flowLayout containing your buttons in your ScrollArea?!

                            I don't know if my layout design is the correct one. I should be able to navigate to the buttons at the bottom from the top buttons by scrolling. This is my objective. How can it be achieved?

                            “ In order to be irreplaceable, one must always be different” – Coco Chanel

                            1 Reply Last reply
                            0
                            • J JKSH
                              16 Dec 2021, 12:23

                              @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                              I want to set the scrolling functionality for the array of pushbuttons. That's the reason why I put scrollArea inside the flowLayout.

                              Then you should:

                              1. Put the flowLayout in a container/child widget
                              2. Put that container/child widget in the scrollArea

                              But before that, simplify your design and remove the widgets and layouts that you don't need. Both myself and @Pl45m4 have asked you to do this. Please don't ignore our words.

                              S Offline
                              S Offline
                              Swati777999
                              wrote on 17 Dec 2021, 01:46 last edited by Swati777999
                              #23

                              @JKSH and @Pl45m4

                              Yes, check the revised code as below:

                              {
                              QWidget *flowWidget = new QWidget(this);
                              FlowLayout *flowLayout = new FlowLayout();
                              flowWidget->setLayout(flowLayout);
                              int n=20;
                              QVector <QPushButton *> buttons(n);
                              
                              for (int ii=0;ii<n;ii++)
                              {
                                    QPushButton * pb = new QPushButton(); // creating buttons
                                     pb->setMinimumSize(200,200);
                                     buttons.push_back(pb); // adding buttons to qvector
                                     flowLayout->addWidget(pb);
                              }
                              
                              QScrollArea *scroll =new QScrollArea(this);
                              scroll->setWidget(flowWidget);
                               this->show();
                              }
                              

                              It gives me following output :
                              Program-1-17.12.PNG
                              scrollArea inside another window .

                              If I declare scroll widget as below:
                              QScrollArea *scroll =new QScrollArea();
                              I get a blank window.

                              If I declare scroll widget as follows:
                              QScrollArea *scroll =new QScrollArea(flowWidget);
                              my program crashes.

                              “ In order to be irreplaceable, one must always be different” – Coco Chanel

                              J 1 Reply Last reply 17 Dec 2021, 02:03
                              0
                              • S Swati777999
                                17 Dec 2021, 01:46

                                @JKSH and @Pl45m4

                                Yes, check the revised code as below:

                                {
                                QWidget *flowWidget = new QWidget(this);
                                FlowLayout *flowLayout = new FlowLayout();
                                flowWidget->setLayout(flowLayout);
                                int n=20;
                                QVector <QPushButton *> buttons(n);
                                
                                for (int ii=0;ii<n;ii++)
                                {
                                      QPushButton * pb = new QPushButton(); // creating buttons
                                       pb->setMinimumSize(200,200);
                                       buttons.push_back(pb); // adding buttons to qvector
                                       flowLayout->addWidget(pb);
                                }
                                
                                QScrollArea *scroll =new QScrollArea(this);
                                scroll->setWidget(flowWidget);
                                 this->show();
                                }
                                

                                It gives me following output :
                                Program-1-17.12.PNG
                                scrollArea inside another window .

                                If I declare scroll widget as below:
                                QScrollArea *scroll =new QScrollArea();
                                I get a blank window.

                                If I declare scroll widget as follows:
                                QScrollArea *scroll =new QScrollArea(flowWidget);
                                my program crashes.

                                J Offline
                                J Offline
                                JKSH
                                Moderators
                                wrote on 17 Dec 2021, 02:03 last edited by
                                #24

                                @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                Yes, check the revised code as below:

                                Good! It is much cleaner now.

                                scrollArea inside another window .

                                That's because your scrollArea is a child widget but you did not put it inside a layout.

                                Questions:

                                1. In your latest code, who is scrollArea's parent?
                                2. Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
                                3. How would you make scrollArea a top-level widget?

                                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                S 1 Reply Last reply 17 Dec 2021, 02:17
                                0
                                • J JKSH
                                  17 Dec 2021, 02:03

                                  @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                  Yes, check the revised code as below:

                                  Good! It is much cleaner now.

                                  scrollArea inside another window .

                                  That's because your scrollArea is a child widget but you did not put it inside a layout.

                                  Questions:

                                  1. In your latest code, who is scrollArea's parent?
                                  2. Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
                                  3. How would you make scrollArea a top-level widget?
                                  S Offline
                                  S Offline
                                  Swati777999
                                  wrote on 17 Dec 2021, 02:17 last edited by Swati777999
                                  #25

                                  @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                  That's because your scrollArea is a **child widget** but you did not put it inside a **layout.
                                  If I write flowLayout ->addWidget(scroll); , my program ends forcefully.

                                  Questions:
                                  1. In your latest code, who is scrollArea's parent?
                                  Ans: the mainwindow (I've set its parent to be this . As mentioned above, if I set it's parent to be flowWidget,my program crashes.

                                  2. Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
                                  Ans : It's like the main window is the parent ; its child is flowWidget whose children are buttons , scroll is to be applied to flowWidget such that scroll functionality works for all the buttons simultaneously.

                                  Note : I should be able to navigate to the buttons at the bottom from the top buttons by scrolling. This is my objective.

                                  3. How would you make scrollArea a top-level widget?
                                  Ans: It was just a part of my experimentation, as it is not working neither for scroll->setWidget(flowWidget) nor for QScrollArea *scroll = new QScrollArea (flowWidget);

                                  I hope it makes much sense now/

                                  “ In order to be irreplaceable, one must always be different” – Coco Chanel

                                  P 1 Reply Last reply 17 Dec 2021, 03:04
                                  0
                                  • S Swati777999
                                    17 Dec 2021, 02:17

                                    @JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                    That's because your scrollArea is a **child widget** but you did not put it inside a **layout.
                                    If I write flowLayout ->addWidget(scroll); , my program ends forcefully.

                                    Questions:
                                    1. In your latest code, who is scrollArea's parent?
                                    Ans: the mainwindow (I've set its parent to be this . As mentioned above, if I set it's parent to be flowWidget,my program crashes.

                                    2. Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
                                    Ans : It's like the main window is the parent ; its child is flowWidget whose children are buttons , scroll is to be applied to flowWidget such that scroll functionality works for all the buttons simultaneously.

                                    Note : I should be able to navigate to the buttons at the bottom from the top buttons by scrolling. This is my objective.

                                    3. How would you make scrollArea a top-level widget?
                                    Ans: It was just a part of my experimentation, as it is not working neither for scroll->setWidget(flowWidget) nor for QScrollArea *scroll = new QScrollArea (flowWidget);

                                    I hope it makes much sense now/

                                    P Offline
                                    P Offline
                                    Pl45m4
                                    wrote on 17 Dec 2021, 03:04 last edited by Pl45m4
                                    #26

                                    @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                    I hope it makes much sense now

                                    Not really, at least not to me.

                                    For what purpose is the FlowWidget now?
                                    Can't you just assign the flowLayout to your mainWindow?

                                    Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
                                    Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widget is as big as the parent window.

                                    Edit:
                                    Quick fix: set your main widget (whatever it might be, maybe scrollArea?!) as centralWidget with setCentralWidget(.....), so the content covers your whole mainWindow.


                                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                    ~E. W. Dijkstra

                                    S 1 Reply Last reply 17 Dec 2021, 03:31
                                    1
                                    • P Pl45m4
                                      17 Dec 2021, 03:04

                                      @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                      I hope it makes much sense now

                                      Not really, at least not to me.

                                      For what purpose is the FlowWidget now?
                                      Can't you just assign the flowLayout to your mainWindow?

                                      Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
                                      Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widget is as big as the parent window.

                                      Edit:
                                      Quick fix: set your main widget (whatever it might be, maybe scrollArea?!) as centralWidget with setCentralWidget(.....), so the content covers your whole mainWindow.

                                      S Offline
                                      S Offline
                                      Swati777999
                                      wrote on 17 Dec 2021, 03:31 last edited by Swati777999
                                      #27

                                      @Pl45m4 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                      For what purpose is the FlowWidget now?

                                      Can't you just assign the flowLayout to your mainWindow?
                                      Yes, this is what I did at the first place but I followed the suggestion of @JKSH for implementing the scrollArea for all button widgets.

                                      Then you should:
                                      Put the flowLayout in a container/child widget
                                      Put that container/child widget in the scrollArea
                                      

                                      So, I put the entire flowlayout inside a flowWidget.

                                      Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
                                      Yes, my buttons are arrays of widgets. I want to enable scrolling property just the way I use this link of this forum ; to be able to navigate from top to bottom of this page where the contents of my windows are buttons.

                                      Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widgets is as big as the parent window.

                                      I want to navigate to the bottom of the mainwindow through the scrollbar where the contents of the mainWindow are buttons , just like the following picture; scrollbar in the bottom and right side. In the figure, there are 20 push buttons but I can only view 12 out of them in my window.

                                      flow_Layout_QPushButtons.PNG

                                      “ In order to be irreplaceable, one must always be different” – Coco Chanel

                                      P 1 Reply Last reply 17 Dec 2021, 04:45
                                      0
                                      • S Swati777999
                                        17 Dec 2021, 03:31

                                        @Pl45m4 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                        For what purpose is the FlowWidget now?

                                        Can't you just assign the flowLayout to your mainWindow?
                                        Yes, this is what I did at the first place but I followed the suggestion of @JKSH for implementing the scrollArea for all button widgets.

                                        Then you should:
                                        Put the flowLayout in a container/child widget
                                        Put that container/child widget in the scrollArea
                                        

                                        So, I put the entire flowlayout inside a flowWidget.

                                        Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
                                        Yes, my buttons are arrays of widgets. I want to enable scrolling property just the way I use this link of this forum ; to be able to navigate from top to bottom of this page where the contents of my windows are buttons.

                                        Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widgets is as big as the parent window.

                                        I want to navigate to the bottom of the mainwindow through the scrollbar where the contents of the mainWindow are buttons , just like the following picture; scrollbar in the bottom and right side. In the figure, there are 20 push buttons but I can only view 12 out of them in my window.

                                        flow_Layout_QPushButtons.PNG

                                        P Offline
                                        P Offline
                                        Pl45m4
                                        wrote on 17 Dec 2021, 04:45 last edited by
                                        #28

                                        @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                        where the contents of the mainWindow are buttons

                                        The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.


                                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                        ~E. W. Dijkstra

                                        S 1 Reply Last reply 17 Dec 2021, 06:44
                                        1
                                        • P Pl45m4
                                          17 Dec 2021, 04:45

                                          @Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:

                                          where the contents of the mainWindow are buttons

                                          The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.

                                          S Offline
                                          S Offline
                                          Swati777999
                                          wrote on 17 Dec 2021, 06:44 last edited by Swati777999
                                          #29

                                          @Pl45m4
                                          The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.
                                          Okay, Let me write the whole function according to your suggestion.

                                          Window::Window()
                                          {
                                          QMainWindow *a= new QMainWindow(this);
                                          
                                          QWidget *flowWidget = new QWidget();
                                          FlowLayout *flowLayout = new FlowLayout();
                                          flowWidget->setLayout(flowLayout);
                                          int n=20;
                                          QVector <QPushButton *> buttons(n);
                                          
                                          for (int ii=0;ii<n;ii++)
                                          {
                                              QPushButton * pb = new QPushButton(); // creating buttons
                                          
                                                 pb->setMinimumSize(200,200);
                                                 buttons.push_back(pb); // adding buttons to qvector
                                          
                                                 flowLayout->addWidget(pb);
                                          
                                          }
                                          
                                          QScrollArea *scroll =new QScrollArea();
                                          scroll->setWidget(flowWidget);
                                          
                                          a->setCentralWidget(scroll);
                                          
                                          
                                          a->show();
                                          
                                          setWindowTitle(tr("Flow Layout"));
                                          }
                                          

                                          I obviously,get 2 windows from the above code, Window1 corresponding to this by default window which is blank.
                                          Window2 is as shown below
                                          Program-2-17.12_window2.PNG

                                          scroll Area is applied to the window but the flowLayout seems not to be working and the widgets take vertical Layout. Can you help me to fix this?

                                          “ In order to be irreplaceable, one must always be different” – Coco Chanel

                                          P J 2 Replies Last reply 17 Dec 2021, 10:35
                                          0

                                          19/52

                                          15 Dec 2021, 06:10

                                          • Login

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