QT Designer Scroll Area not working as expected.



  • Hello all!

    I am an Autodesk maya 2011 user and I am trying to create a UI in QT with a Scroll Area in it.
    However so far I have not been able to get it working. I searched a lot for this problem but so far I have not found anyone with a similar problem.
    I also checked the help file on this problem but the scroll area topic in the help file only focuses on using scroll area's within code.
    As far as I know I can not use any form of scripting/code except for the script in the UI file itself since Autodesk Maya only reads the UI file. Other than that I am a complete novice using QT. :)

    Problem:

    When I create a Scroll Area in a mainWindow and place any layout or widget inside of it that is larger than the Scroll Area the Scroll area does not show any Scroll bars. Even if I set the verticalScrollBarPolicy to alwaysOn then it only shows a grayed out scrollbar.
    In QT aswell as in maya (ofcourse)

    Do I need to do anything extra in order to make the Scroll Area work.

    Any help or suggestions would be most appreciated.

    Thanks!!

    Red


  • Moderators

    Hi, I cannot reproduce your problem. Here is an example file I created:

    @<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Form</class>
    <widget class="QWidget" name="Form">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Form</string>
    </property>
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
    <widget class="QScrollArea" name="scrollArea">
    <property name="widgetResizable">
    <bool>true</bool>
    </property>
    <widget class="QWidget" name="scrollAreaWidgetContents">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>96</width>
    <height>26</height>
    </rect>
    </property>
    <widget class="QListView" name="listView">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>300</width>
    <height>300</height>
    </rect>
    </property>
    <property name="minimumSize">
    <size>
    <width>300</width>
    <height>300</height>
    </size>
    </property>
    </widget>
    </widget>
    </widget>
    </item>
    </layout>
    </widget>
    <resources/>
    <connections/>
    </ui>@

    Scrollareas show up nicely on demand for me.



  • Hey,

    thank you for your explanation.

    I have tried to open the file you created as UI file but then QT gives an error.

    Cannot open file: (file path)

    I am now trying to reproduce your code to see if that will work.


  • Moderators

    Actually the forum decided to 'cryptify' the qml file posted ... Just remove the very first line (xml version="1.0" etc), it should then load fine.



  • Eureka !!

    I now understand what I missed. I had to layout contents of the scroll area.
    Like you put the scroll area within a grid layout.

    Thanks again for your help !



  • redace, can you explain how you "layout the contents" of the scroll bar? I'm using some code from an example in Qt Assistant but it isn't working. This is an excerpt from what's in Qt Assistant:

    @ QSize areaSize = viewport()->size();
    QSize widgetSize = widget->size();

     verticalScrollBar()->setPageStep(widgetSize.height());
     horizontalScrollBar()->setPageStep(widgetSize.width());
     verticalScrollBar()->setRange(0, widgetSize.height() - areaSize.height());@
    

    Are you using something similar to that?



  • Hey,

    It has been a while since I worked with QT.
    However I never used qt assistant. Only qt creator.

    I have no idea how I can layout the contents of the scroll bar itself.
    Below you can find the code of a .UI file with a simple scroll field so you can check it out for yourself.
    Maybe it is of some use to you.

    Hope it helps.

    @<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>315</width>
    <height>489</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <widget class="QScrollArea" name="scrollArea">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>40</y>
    <width>261</width>
    <height>411</height>
    </rect>
    </property>
    <property name="widgetResizable">
    <bool>true</bool>
    </property>
    <widget class="QWidget" name="scrollAreaWidgetContents">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>318</width>
    <height>518</height>
    </rect>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout">
    <item>
    <widget class="QFrame" name="frame">
    <property name="minimumSize">
    <size>
    <width>300</width>
    <height>500</height>
    </size>
    </property>
    <property name="sizeIncrement">
    <size>
    <width>200</width>
    <height>0</height>
    </size>
    </property>
    <property name="baseSize">
    <size>
    <width>0</width>
    <height>0</height>
    </size>
    </property>
    <property name="frameShape">
    <enum>QFrame::StyledPanel</enum>
    </property>
    <property name="frameShadow">
    <enum>QFrame::Raised</enum>
    </property>
    <widget class="QPushButton" name="pushButton">
    <property name="geometry">
    <rect>
    <x>170</x>
    <y>250</y>
    <width>75</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    <widget class="QPushButton" name="pushButton_2">
    <property name="geometry">
    <rect>
    <x>80</x>
    <y>470</y>
    <width>75</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    </widget>
    </item>
    </layout>
    </widget>
    </widget>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.