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. Scrollbars don't show
QtWS25 Last Chance

Scrollbars don't show

Scheduled Pinned Locked Moved Solved General and Desktop
scrollbar
13 Posts 5 Posters 8.2k 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I need a vertical scroll bar in mainwindow.ui. It doesn't come up automatically when a widget becomes hidden. What is the best way to display scroll bars?
    Thank you.

    RatzzR 1 Reply Last reply
    0
    • G gabor53

      Hi,
      I need a vertical scroll bar in mainwindow.ui. It doesn't come up automatically when a widget becomes hidden. What is the best way to display scroll bars?
      Thank you.

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @gabor53
      Here is one example.

      --Alles ist gut.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        Can I use QDialog as widget for scroll bar?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          simply use a QScrollArea

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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gabor53
            wrote on last edited by
            #5

            I added QScrollArea. Only a rectangle appeared without arrows. What did I do incorrectly?
            (I added in Designer).
            Thank you.

            raven-worxR 1 Reply Last reply
            0
            • G gabor53

              I added QScrollArea. Only a rectangle appeared without arrows. What did I do incorrectly?
              (I added in Designer).
              Thank you.

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

              @gabor53
              probably you either haven't set a child widget, so no scrollbars are necessary.
              Or you need to adapt the scrollarea's scrollbar-policy.

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

              1 Reply Last reply
              1
              • G Offline
                G Offline
                gabor53
                wrote on last edited by
                #7

                I used the following code to add the scroll bar to the window:

                
                    QScrollArea *scroll = new QScrollArea(this);
                    scroll->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
                    scroll->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
                
                    QWidget *viewport  = new QWidget(this);
                    scroll->setWidget (viewport);
                    scroll->setWidgetResizable (true);
                
                	QHBoxLayout *l = new QHBoxLayout(viewport);
                    viewport->setLayout (l);
                
                    //Add widgets
                    l->addWidget (ui->label);
                    l->addWidget (ui->ID_Display);
                
                
                
                    QHBoxLayout *dialog_layout = new QHBoxLayout(this);
                    this->setLayout(dialog_layout);
                    this->layout ()->addWidget (scroll);
                    this->show ();
                

                It does add the scroll bar, but when I add the widgets They appear randomly in the window opened. How can I keep the original design?

                Thank you.

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  N.Sumi
                  wrote on last edited by N.Sumi
                  #8

                  Hi @gabor53

                  you get scroll bars only when you set the child widgets in it,. No child widget means, you don't need/ get any scroll bars.
                  By default, the scroll bars are displayed only when the viewport is smaller than the child widget. You can force the scroll bars to always be shown by setting scroll bar policies.

                  QScrollArea scrollArea;
                  scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
                  scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

                  I made a small sample with Designer , you can check this.

                  https://www.dropbox.com/sh/sw0hxogg3x9xq3e/AADwVRL6NSZtLK_8q2iOgLPIa?dl=0

                  Q 1 Reply Last reply
                  2
                  • G Offline
                    G Offline
                    gabor53
                    wrote on last edited by
                    #9

                    I created a scroll area in Designer and moved all the widget into the scroll area. I see the widgets, and there are scroll bars on the side but they are inactive. How can I set the view area in a way, that when some of the widgets are off the screen the scrollbars show and work?
                    Thank you.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gabor53
                      wrote on last edited by
                      #10

                      I created the following in Designer. It is clear that several lineEdits can't be seen, but there is still no sidebar. Any Idea why? Thank you.

                      [Files]([https://www.dropbox.com/sh/wkyuq64trxk2lrq/AAAmWPeosw4qSUSkJj9AQG5fa?dl=0](link url))

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        N.Sumi
                        wrote on last edited by
                        #11

                        Hi @gabor53

                        Seems the problem is with QDialog & you have used layout wrongly.

                        Refer to this link, if you are going QDialog. You have solution.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gabor53
                          wrote on last edited by
                          #12

                          Thank you. It worked.

                          1 Reply Last reply
                          0
                          • N N.Sumi

                            Hi @gabor53

                            you get scroll bars only when you set the child widgets in it,. No child widget means, you don't need/ get any scroll bars.
                            By default, the scroll bars are displayed only when the viewport is smaller than the child widget. You can force the scroll bars to always be shown by setting scroll bar policies.

                            QScrollArea scrollArea;
                            scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
                            scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

                            I made a small sample with Designer , you can check this.

                            https://www.dropbox.com/sh/sw0hxogg3x9xq3e/AADwVRL6NSZtLK_8q2iOgLPIa?dl=0

                            Q Offline
                            Q Offline
                            Qt_Python Learner
                            wrote on last edited by Qt_Python Learner
                            #13

                            @N-Sumi @gabor53 Hey, Sorry I get that this is quite old post. But asking incase if you have a solution. I understood how to add this in code and get it. But is there a way to set this property in QtDesigner? So that every time I modify my design, I need not type explicitly in the generated code. I cannot find this property. Could you please let me know if we can do this in Qt designer

                            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