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. QScrollarea in verticalLayout

QScrollarea in verticalLayout

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 2.9k 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.
  • H Offline
    H Offline
    hjohn
    wrote on last edited by
    #1

    Can not scroll the buttons created using Vertical Layout.

    widget.cpp

    #include "widget.h"
    #include "ui_widget.h"
    #include<QScrollArea>
    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
      
    
        QScrollArea *area=new QScrollArea(this);
        area->setLayout(ui->verticalLayout);
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    

    output:
    0_1530858821484_Untitled.png

    raven-worxR 1 Reply Last reply
    0
    • H hjohn

      Can not scroll the buttons created using Vertical Layout.

      widget.cpp

      #include "widget.h"
      #include "ui_widget.h"
      #include<QScrollArea>
      Widget::Widget(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::Widget)
      {
          ui->setupUi(this);
        
      
          QScrollArea *area=new QScrollArea(this);
          area->setLayout(ui->verticalLayout);
      }
      
      Widget::~Widget()
      {
          delete ui;
      }
      

      output:
      0_1530858821484_Untitled.png

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @hjohn said in QScrollarea in verticalLayout:

      QScrollArea *area=new QScrollArea(this);
      area->setLayout(ui->verticalLayout);

      because thats not how you set content to a QScrollArea.
      You should use QScrollArea::setWidget()

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      H 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @hjohn said in QScrollarea in verticalLayout:

        QScrollArea *area=new QScrollArea(this);
        area->setLayout(ui->verticalLayout);

        because thats not how you set content to a QScrollArea.
        You should use QScrollArea::setWidget()

        H Offline
        H Offline
        hjohn
        wrote on last edited by
        #3

        @raven-worx
        which widget i have to set?
        I mean first i am adding layout and then adding buttons on it from Qt designer

        raven-worxR 1 Reply Last reply
        0
        • H hjohn

          @raven-worx
          which widget i have to set?
          I mean first i am adding layout and then adding buttons on it from Qt designer

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @hjohn said in QScrollarea in verticalLayout:

          which widget i have to set?

          any widget.

          QWidget* w = new QWidget( this );
          w->setLayout(ui->verticalLayout);
          QScrollArea *area = new QScrollArea(this);
          area->setWidget(w);
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          H 1 Reply Last reply
          5
          • raven-worxR raven-worx

            @hjohn said in QScrollarea in verticalLayout:

            which widget i have to set?

            any widget.

            QWidget* w = new QWidget( this );
            w->setLayout(ui->verticalLayout);
            QScrollArea *area = new QScrollArea(this);
            area->setWidget(w);
            
            H Offline
            H Offline
            hjohn
            wrote on last edited by
            #5

            @raven-worx Its Done..Thank you very much for quick reply.thanks for Help. :)

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hjohn
              wrote on last edited by
              #6

              widget.cpp

              #include "widget.h"
              #include "ui_widget.h"
              
              #include<QScrollArea>
              #include<QPushButton>
              #include<QDebug>
              Widget::Widget(QWidget *parent) :
                  QWidget(parent),
                  ui(new Ui::Widget)
              {
                  ui->setupUi(this);
              
                  QWidget *W=new QWidget(this);
                  
                  W->setLayout(ui->verticalLayout);
              
              
              
                  QScrollArea *area=new QScrollArea(this);
                      area->setWidget(W);
              
              }
              
              Widget::~Widget()
              {
                  delete ui;
              }
              
              

              output :
              0_1530867116274_1.png

              as its visible in the image , it doesn't look proper. How do I fix it ?

              raven-worxR 1 Reply Last reply
              0
              • H hjohn

                widget.cpp

                #include "widget.h"
                #include "ui_widget.h"
                
                #include<QScrollArea>
                #include<QPushButton>
                #include<QDebug>
                Widget::Widget(QWidget *parent) :
                    QWidget(parent),
                    ui(new Ui::Widget)
                {
                    ui->setupUi(this);
                
                    QWidget *W=new QWidget(this);
                    
                    W->setLayout(ui->verticalLayout);
                
                
                
                    QScrollArea *area=new QScrollArea(this);
                        area->setWidget(W);
                
                }
                
                Widget::~Widget()
                {
                    delete ui;
                }
                
                

                output :
                0_1530867116274_1.png

                as its visible in the image , it doesn't look proper. How do I fix it ?

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @hjohn said in QScrollarea in verticalLayout:

                it doesn't look proper. How do I fix it ?

                define proper. What exactly do you want to achieve?

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                H 1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @hjohn said in QScrollarea in verticalLayout:

                  it doesn't look proper. How do I fix it ?

                  define proper. What exactly do you want to achieve?

                  H Offline
                  H Offline
                  hjohn
                  wrote on last edited by hjohn
                  #8

                  @raven-worx Proper:Without horizontal scrollBar, I mean if we want to see the whole button we have to scroll . I don't want to scroll horizontally.

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    hjohn
                    wrote on last edited by
                    #9

                    Okay its done ,
                    I just resized the QScrollArea.
                    Thanks all.

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

                      Hi,

                      Since you are using Designer, why don't you put the QScrollArea directly in your ui ?

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

                      H 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Hi,

                        Since you are using Designer, why don't you put the QScrollArea directly in your ui ?

                        H Offline
                        H Offline
                        hjohn
                        wrote on last edited by
                        #11

                        @SGaist I had to implement the QScrollArea by means of code.

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

                          Why is that ?

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

                          H 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Why is that ?

                            H Offline
                            H Offline
                            hjohn
                            wrote on last edited by
                            #13

                            @SGaist Firstly I used the ScrollArea from UI, and it worked fine, So I wanted use QScrollArea by code. Just for learning purpose.

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

                              Then I'd recommend to start by doing the whole interface in code only. Once you are confortable with that, you can start mixing designer and code generate widgets.

                              There are subtleties when mixing that you have to take into account.

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

                              H 1 Reply Last reply
                              1
                              • SGaistS SGaist

                                Then I'd recommend to start by doing the whole interface in code only. Once you are confortable with that, you can start mixing designer and code generate widgets.

                                There are subtleties when mixing that you have to take into account.

                                H Offline
                                H Offline
                                hjohn
                                wrote on last edited by
                                #15

                                @SGaist yeah thanks..

                                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