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. What's relationship between viewport(), widget() and QScrollArea
Qt 6.11 is out! See what's new in the release blog

What's relationship between viewport(), widget() and QScrollArea

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 28.4k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fifth
    wrote on last edited by
    #1

    I thought they were same, eventually I was wrong.
    Now I'm totally confused with their relationship.

    Here's my understanding,

    1. QScrollArea is the outmost container widget, it contains scrollbars and viewport widget.
    2. I've no idea about what purpose of viewport widget is.
    3. widget() represents real contents, holding other subwidgets, for example.
      Did I get right?
    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi fifth,

      if you read the docs, it is stated:

      bq. QAbstractScrollArea is a low-level abstraction of a scrolling area. The area provides a central widget called the viewport, in which the contents of the area is to be scrolled (i.e, the visible parts of the contents are rendered in the viewport).
      Next to the viewport is a vertical scroll bar, and below is a horizontal scroll bar. When all of the area contents fits in the viewport, each scroll bar can be either visible or hidden depending on the scroll bar's Qt::ScrollBarPolicy. When a scroll bar is hidden, the viewport expands in order to cover all available space. When a scroll bar becomes visible again, the viewport shrinks in order to make room for the scroll bar.

      "see QAbstractScrollArea Description":http://doc.qt.nokia.com/4.7/qabstractscrollarea.html#details

      so in short:

      QScrollArea is the outmost container widget, it contains scrollbars and viewport widget. --> correct

      viewport is the area, the visible stuff is rendered to

      widget() represents the content, you added. It might be bigger than the QScrollArea Widget.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Franzk
        wrote on last edited by
        #3

        Think of the viewport() as a rectangle through which you are looking at the widget(). The scrollbars determine above which part of the widget() the viewport() is floating. It is even possible to use a custom viewport. This is mostly used in the graphics scene/view framework, where it is used to set the viewport to an QGLWidget. However, you can also make a custom widget that allows you to zoom in or out on a widget using a transformation matrix. There are a lot of different possibilities by using the viewport.

        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        • Login

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