QScrollArea with mixed content, how to scroll that no labels or QLineedits will be cut off?`



  • Hi all,

    i am currently working on a embedded solution which has a LCD attached + keypad.

    I have a Widget where the IP settings can be configured.
    The Widget has a QScrollArea which contains a Gridlayout with several Labels and regarding QLineEdits.

    The problem is now, if I move the focus (using keyboard) down or up, the labels and QLineEdits can be cut off at the beginning or the end of the scrollarea.

    I know this is normal windows behaviour, but how can I achieve it that the labels and the regarding QLineEdit will be always fully viewable without having them cut off?

    So target solution shall be if I scroll up/down the elements which are shown in the ScrollArea shall not be cut off.

    Is there some generic solution or idea how to achieve it?

    I already tried using offset and redrawing, but this will be a lot of effort for the widgets, so I am searching for a more generic and smarter solution.

    Many Thanks in advance


  • Qt Champions 2016

    @BluTiGeS said:

    Have you tried
    http://doc.qt.io/qt-5.5/qscrollarea.html#ensureWidgetVisible

    on the widget you wish to be fully visible?



  • @mrjj
    Thank you for your reply, I tried:

    ui->scrollArea->ensureWidgetVisible( ui->label );

    but the label is still cut off, do I am using it wrong?
    The label which shall not be cut off is insige a gridlayout of the scrollarea.

    Many Thanks


  • Qt Champions 2016

    @BluTiGeS
    Well I used it on a widget that hold the other elements.
    I added some y margin before i liked it fully.

    You must call it when you navigate. Like on keypress. then call it.
    Since I think you have more than one label,
    ensureWidgetVisible( ui->label );
    seems wrong?

    You can use event filter to catch changing focus
    QObject::installEventFilter()
    http://www.qtforum.org/article/2532/how-can-i-emit-a-signal-when-a-lineedit-is-focused.html

    Then ensureWidgetVisible.

    You cant just call it once.



  • @mrjj
    Ahh okay I see, but this will not prevent the cut off of the other elements, but I am thinking if I go this way how to ensure that the previous label is also be shown?

    So if

    Some content
    Label
    Button

    is in the scrollara and the ensure is set to the button, how to make sure that the label before is also fully visible in combiantion with the button a line below?

    see:
    https://picload.org/image/pcwcrao/2015-11-2018_16_33-filmetv.png

    There the buttons are still cut off. It would be nice if the elements are always fully displayed and scrolled elementwise.

    The scrollarea height is fixed, so no resize possible on the target.

    Any idea for this issue?


  • Qt Champions 2016

    well you can maybe adjust scroll amount
    ui->scrollArea->verticalScrollBar()->setSingleStep(25);
    so it matches the height you want.
    so each scroll would scroll one "row" height being
    what ever u want.
    So the last one is never cut.



  • Settings the scrollheight would fit if the height is always the same.
    But how to get it Händler more dynammically if for example one "row" has a different height?

    I am really thinking about a generic solution for multiple pages/Widgets.

    So any help is appreciated also thanks for currently answers.

    Some further thougt s ;) how to get this done for different "row" heights?



  • Does anyone have a further solution or hint, how this could be achieved?
    I cannot imagine this was never done with Qt ;).

    Many Thanks

    Regards


  • Lifetime Qt Champion

    Hi,

    You can try to use ensureWidgetVisible by calling it if e.g. the scroll bar has not been moved for a certain amount of time.

    Hope it helps


Log in to reply
 

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