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. QT ScrollBars doesn't appear with scrollAreaWidgetContents

QT ScrollBars doesn't appear with scrollAreaWidgetContents

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt scrollarea
5 Posts 3 Posters 2.0k 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.
  • N Offline
    N Offline
    nipunamr
    wrote on last edited by
    #1

    I am trying to learn QT with visual studio. My development environment is VS2015 with QT designer. I am trying to do the following tutorial.

    http://www.bogotobogo.com/Qt/Qt5_QMainWindow_QAction_ImageViewer_B.php

    essentially the tutorial displays an image with Qlabel and QScrollArea. If I create the widgets with code (using visual studio) the program seems to work.

     imageLabel = new QLabel;
     imageLabel->setBackgroundRole(QPalette::Base);
     imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
     imageLabel->setScaledContents(true);
    
     scrollArea = new QScrollArea;
     scrollArea->setBackgroundRole(QPalette::Dark);
     scrollArea->setWidget(imageLabel);
     setCentralWidget(scrollArea);
    

    However, then I tried to do the same with QT Designer. When I dragged a ScrollArea from QT Designer, I noticed that it also created a QWidget called "scrollAreaWidgetContents". Then when I created the QLabel, Label was created under "scrollAreaWidgetContents" widget. I then tried to display the image using the following code.

    ui->label->setBackgroundRole(QPalette::Base);
    ui->label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    ui->label->setScaledContents(true);
    
    ui->scrollArea->setBackgroundRole(QPalette::Dark);
    ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
    ui->scrollArea->setWidgetResizable(true);
    ui->scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    //ui->scrollArea->setWidget(ui->label);
    setCentralWidget(ui->scrollArea);
    

    The problem with this is that the scroll Bars never appears.

    Then I uncommented "ui->scrollArea->setWidget(ui->label);" line and then the program compiles but crashes. So, how do I make the scrollBars appear with QT Designer? What am I doing wrong.

    Thanks for the help

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

      Hi and welcome to devnet,

      IIRC, you can use the "promote to" feature and make that widget a QLabel.

      Hope it helps

      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
      • N Offline
        N Offline
        nipunamr
        wrote on last edited by
        #3

        I tired it but it didn't let me promote QWidget ("scrollAreaWidgetContents") to QLabel. It said QLabel aleardy exists. I tried it using QT Designer.

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

          An alternative could be to just edit the .ui file directly and change scrollAreaWidgetContents to a QLabel. Would likely be faster.

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

            I know this is an old thread but I just want to chip in to this.

            I got this exact problem trying to put anything into a QScrollBar in designer and they just don't work because of this stupid dummy "scrollAreaWidgetContents" that was auto created. It cannot be modified or deleted.

            The only workaround I found is to do everything in the main cpp, creating the image label and adding it to the QScrollArea object, skipping the scrollAreaWidgetContents, which completely took away the convenience of using the 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