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 not showing up

ScrollBars not showing up

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 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.
  • S Offline
    S Offline
    smoyertech
    wrote on last edited by
    #1

    I know this topic is similar to others I have found but I cannot get either vertical or horizontal scrollbars to show up when the imageViewport is bigger than the scrollArea. There are two of us learning Qt here and neither one of us have been able to figure this one out. Hopefully it is something simple. Any help much appreciated ...

    Using Designer/Creator Qt 5.5.1, I have created a standard Qt Windows desktop application with a QMainWindow called EpoieReplacement, which contains a centralWidget, which contains a QscrollArea called scrollArea, which contains a QWidget called scrollAreaWidgetContents and a QLabel called imageViewport.

    QMainWindow EpoieReplacement 
        QWidget centralWidget
            QScrollAreascrollArea
                QWidget scrollAreaWidgetContents
                QLabel imageViewport 
    

    The scrollArea is set to ScrollBarAsNeeded for both v and h scrollbars.

    Here is the pertinent code created by the Designer in the ui_EpoieReplacement.h file:
    (No title/menu/tool/status bar code included here, as that all works fine)

        centralWidget = new QWidget(EpoieReplacement);
        centralWidget->setObjectName(QStringLiteral("centralWidget"));
        scrollArea = new QScrollArea(centralWidget);
        scrollArea->setObjectName(QStringLiteral("scrollArea"));
        scrollArea->setGeometry(QRect(0, 0, 981, 711));
        scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        scrollArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
        scrollArea->setWidgetResizable(true);
        scrollAreaWidgetContents = new QWidget();
        scrollAreaWidgetContents->setObjectName(QStringLiteral("scrollAreaWidgetContents"));
        scrollAreaWidgetContents->setGeometry(QRect(0, 0, 979, 709));
        QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
        sizePolicy.setHorizontalStretch(0);
        sizePolicy.setVerticalStretch(0);
        sizePolicy.setHeightForWidth(scrollAreaWidgetContents->sizePolicy().hasHeightForWidth());
        scrollAreaWidgetContents->setSizePolicy(sizePolicy);
        imageViewport = new QLabel(scrollAreaWidgetContents);
        imageViewport->setObjectName(QStringLiteral("imageViewport"));
        imageViewport->setGeometry(QRect(0, 0, 1071, 221));
        imageViewport->setScaledContents(true);
        scrollArea->setWidget(scrollAreaWidgetContents);
        EpoieReplacement->setCentralWidget(centralWidget);
    

    Here is the pertinent code in the QMainWindow (EpoieReplacement) constructor:

    ui->setupUi(this);
    
    ui->imageViewport = ui->imageViewport;
    ui->imageViewport->setBackgroundRole(QPalette::Base);
    ui->imageViewport->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    ui->imageViewport->setScaledContents(true);
    
    ui->scrollArea->setBackgroundRole(QPalette::Dark);
    ui->scrollArea->setWidgetResizable(true);
    ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
    setCentralWidget(ui->scrollArea);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Your imageViewport widget is "floating" in scrollAreaWidgetContents. You should put it in a layout that is set on scrollAreaWidgetContents.

      You should take a look at the Image Viewer Example.

      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
      1
      • S Offline
        S Offline
        smoyertech
        wrote on last edited by
        #3

        Thanks for the response, SGaist. The Image Viewer Example is the example I followed, except that it does not use Designer. Guess I'll have to figure out how to put the imageViewport widget in a layout that is set on scrollAreaWidgetContents, unless someone can explain to me how to do that in Designer.

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

          It's explained in the Designer Layouts part of Designer's documentation.

          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
          • S Offline
            S Offline
            smoyertech
            wrote on last edited by
            #5

            Not sure you will be able to access this image url but it shows that both centralWidget and scrollAreaWidgetContents Widgets with grid layout icons, but both have a red circle with a line through it on top of the grid layout icon, and I don't know what that means.

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

              No I can't see it however from your description it looks like you have no layout applied on the widget.

              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
              • S Offline
                S Offline
                smoyertech
                wrote on last edited by
                #7

                Thanks. I now have scroll bars which scroll the image up/down and left/right when the imageViewport is bigger than the scrollArea. Just need to figure out what to set to force the scroll bars to adjust when I resize the image and to disappear when the imageViewport is resized to be smaller than the scrollArea.

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

                  With the AsNeeded policy it should already be the case. Are you sure you are resizing the right element ?

                  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

                  • Login

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