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. Determine if widget is in viewport of scrollarea

Determine if widget is in viewport of scrollarea

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    AlexanderB
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlexanderB
        wrote on last edited by
        #3

        Hi MrJJ,

        Exactly that yes.

        mrjjM 1 Reply Last reply
        0
        • A AlexanderB

          Hi MrJJ,

          Exactly that yes.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @alexanderb
          Hi
          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();
          }
          
          1 Reply Last reply
          2
          • A Offline
            A Offline
            AlexanderB
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AlexanderB
              wrote on last edited by
              #6

              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
              }
              
              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved