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 issue inside an embedded widget

QScrollArea issue inside an embedded widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 724 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.
  • X Offline
    X Offline
    xtingray
    wrote on last edited by
    #1

    Hi,
    I'm using a QScrollArea object to contain a set of widgets inside a QDialog instance. Everything works fine, but the QScrollArea doesn't show neither the horizontal or vertical scrollbars when it should. The funny part is that the viewport works fine as I test the code from a touch screen. I mean, the QScrollArea is working although I can't see the scrollbars. Why they are not visible? What I am missing?
    This is my code. I appreciate any hint:

    Dialog::Dialog(QWidget *parent) : QDialog(parent) 
    {
        setStyleSheet("QDialog { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(100, 100, 100), stop:1 rgb(30, 30, 30)); }");
    
        QScrollArea *workArea = new QScrollArea;
        workArea->setWidgetResizable(true);
        workArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
    
        workArea->setWidget(bigPanel());
    
        QBoxLayout *innerLayout = new QVBoxLayout;
        innerLayout->addWidget(workArea);
        
        QWidget *innerWidget = new QWidget;
        innerWidget->setLayout(innerLayout);
    
        QHBoxLayout *globalLayout = new QHBoxLayout;
        globalLayout->addWidget(innerWidget);
        setLayout(globalLayout); 
    }
    
    QWidget * Dialog::bigPanel()
    {
        QWidget *widget = new QWidget;
        QVBoxLayout *contentLayout = new QVBoxLayout;
       
        contentLayout->addWidget(...);
        ...
        ...
        contentLayout->addWidget(...);
        contentLayout->addWidget(...);
    
        widget->setLayout(contentLayout);
        return widget;
    }
    

    Qt Developer

    jsulmJ 1 Reply Last reply
    0
    • X xtingray

      Hi,
      I'm using a QScrollArea object to contain a set of widgets inside a QDialog instance. Everything works fine, but the QScrollArea doesn't show neither the horizontal or vertical scrollbars when it should. The funny part is that the viewport works fine as I test the code from a touch screen. I mean, the QScrollArea is working although I can't see the scrollbars. Why they are not visible? What I am missing?
      This is my code. I appreciate any hint:

      Dialog::Dialog(QWidget *parent) : QDialog(parent) 
      {
          setStyleSheet("QDialog { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(100, 100, 100), stop:1 rgb(30, 30, 30)); }");
      
          QScrollArea *workArea = new QScrollArea;
          workArea->setWidgetResizable(true);
          workArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
      
          workArea->setWidget(bigPanel());
      
          QBoxLayout *innerLayout = new QVBoxLayout;
          innerLayout->addWidget(workArea);
          
          QWidget *innerWidget = new QWidget;
          innerWidget->setLayout(innerLayout);
      
          QHBoxLayout *globalLayout = new QHBoxLayout;
          globalLayout->addWidget(innerWidget);
          setLayout(globalLayout); 
      }
      
      QWidget * Dialog::bigPanel()
      {
          QWidget *widget = new QWidget;
          QVBoxLayout *contentLayout = new QVBoxLayout;
         
          contentLayout->addWidget(...);
          ...
          ...
          contentLayout->addWidget(...);
          contentLayout->addWidget(...);
      
          widget->setLayout(contentLayout);
          return widget;
      }
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @xtingray Did you try to set Qt::ScrollBarAlwaysOn via http://doc.qt.io/qt-5.7/qabstractscrollarea.html#horizontalScrollBarPolicy-prop and http://doc.qt.io/qt-5.7/qabstractscrollarea.html#verticalScrollBarPolicy-prop? Qt::ScrollBarAsNeeded is the default but maybe it's not set for some reason?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      X 1 Reply Last reply
      1
      • jsulmJ jsulm

        @xtingray Did you try to set Qt::ScrollBarAlwaysOn via http://doc.qt.io/qt-5.7/qabstractscrollarea.html#horizontalScrollBarPolicy-prop and http://doc.qt.io/qt-5.7/qabstractscrollarea.html#verticalScrollBarPolicy-prop? Qt::ScrollBarAsNeeded is the default but maybe it's not set for some reason?

        X Offline
        X Offline
        xtingray
        wrote on last edited by xtingray
        #3

        @jsulm Looking for any kind of quick solution I tried:

        1. To add manually scrollbars using setVerticalScrollBar(QScrollBar *) and setHorizontalScrollBar(QScrollBar *)
        2. To set both scrrollbar policies manually using setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy) and setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy) and setting both as Qt::ScrollBarAlwaysOn to force them to show up

        With no luck :(

        Now, what is the funny thing? If I set the QScrollArea object in the external widget, the scrollbars show up and work perfectly. I mean, my problem seems to be related to the fact that I am setting the QScrollArea as part of a QWidget embedded inside another one. Is that a restriction for the QScrollArea class? What I am doing wrong?


        Qt Developer

        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