Important: Please read the Qt Code of Conduct -

Determine if widget is in viewport of scrollarea

  • Hi all,

    I am looking for a way to check if a widget is in the viewport of a scrollarea. How can I do this? I've already been looking through the docs and forum for a while, but can't find a solution yet.

    What I want to do is to mark items that are in view (after an amount of time). Perhaps there is another way to do this, if so, I'd be open for suggestions!

  • Lifetime Qt Champion

    Do you mean
    to check if the Widget is currently visible in the scrollarea?

  • Hi MrJJ,

    Exactly that yes.

  • Lifetime Qt Champion

    well you can use visibleRegion.
    its null when not into "view"
    but it only need 1 pixel to be visible.

    auto list =  ui->scrollAreaWidgetContents-> findChildren< QWidget * >( QString(),Qt::FindDirectChildrenOnly );
    for ( auto widget : list) {
        qDebug() << "visisble:" <<  (  ! widget->visibleRegion().isNull() ) << widget->objectName();

  • @mrjj

    Thanks! It never occurred to me to look at widget, I was looking at ScrollArea.. Too bad there is no method on a ScrollArea to get all visible items.
    While this is not exactly what I need, I think I can use visibleRegion to determine if a widget is fully in view or not.

  • For anyone who cares, instead of looking at visibleRegion.isNull(), I use the region to compare the visible size with the actual size of the widget. That way I can determine when I want the item to be marked.

    Currently I simply use something like:

    if (!widget->visibleRegion().isNull() && widget->visibleRegion().boundingRect().height() == widget->height()) {
      // do something here

Log in to reply