From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


problem in adding many Widgets to QScrollArea and keep the size gentle



  • Hi,
    It a while I am working on a project with Qt and need to add many Widgets on a QScrollArea. All Widgets added to QFormLayout and layout added to scroll area. The problem is that after execution my dialog size expand to fit all widgets (without any scroll bar!). What I want is that the size doesn't change and I could scroll over widgets.

    I tried setWidgetResizable function (set to true) but didn't work.

    The whole layout of my software is like this:

    • there is a QDialog,
    • inside Dialog there is a QTabWidget (and each tab has a QWidget)
    • some tab widget composed of many (QLabel, QLineEdit) which addedd to a QFormLayout
    • QFormLayout added to QScrollArea as layout
    • QScrollArea added to QVBoxLayout as widget
    • and finally QVBoxLayout set as main layout of QDIalog with (setLayout)

    Thanks


  • Lifetime Qt Champion

    Hi
    The setup sounds ok. But i wonder if you use QLabel to show images ?
    Those tend to expand to full image size and make parent grow.



  • no just simple label for every QLineEdit
    accually it is combination of QLabel and either QLineEdit/QCheckBox/QComboBox


  • Lifetime Qt Champion

    @Arash-Shirvan
    hmm, i cant reproduce from the layout u describe
    alt text

    it stays the same size when executed.

    I wonder if its due to dialog and not mainwindow or something completely else.

    Hmm nope
    Dialog stays same size too
    alt text


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    QScrollArea takes a widget to make its magic, setting a layout on the area is wrong.



  • Thanks guys for the tips, exactly the problem was I didin't use a widget in scroll area.

    well I think next time I should give some source code :)

    again thanks for the help.



  • @mrjj my problem solved, but I just wanted to say that the only different about the setup I mentioned was that there was a MainWindow and splitter which contained the Dialog.

    I wish I had enough priviledge to share the striped portion of the source code for reference.


  • Lifetime Qt Champion

    @Arash-Shirvan
    well i didnt get issue as im using Designer that comes with a widget
    in place ( for scrollArea) . so i missed the fact you didnt add widget and layout to that. :)


Log in to reply