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. Scrolling over a series of buttons
Forum Updated to NodeBB v4.3 + New Features

Scrolling over a series of buttons

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.9k 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.
  • J Offline
    J Offline
    jesuisbenjamin
    wrote on last edited by
    #1

    Hello,

    I'd like to build an interface with a series of button aligned horizontally. The series will be wider than the window or screen and therefore it should be scrolled over. I would like the scrolling to occur not per pixels, but per button (so the scroll snaps to the buttons edge so to speak).

    How can I achieve that?

    I thought of using a QScrollArea, but it can have only one child, so buttons should be added horizontally to a QFrame for instance, and the QFrame would be set as child to QScrollArea. But then, how to ensure the per-button scrolling rather than per-pixel?

    Or is there a better way to do this? What do you reckon?

    Thanks.
    B.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

      I think you will need to use ensureWidgetVisible(): perhaps subclass and override scrollContentsBy() to check to see if they have scrolled enough to snap to the next widget?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jesuisbenjamin
        wrote on last edited by
        #3

        Thanks Chris,

        First of all I am not really confident with overriding scrollContentsBy() because I am not sure I understand what it really does.
        Second, if I understand what ensureWidgetVisible() does¹, then how can I tell which widget should be passed as the argument?
        Logically, I'd need to find out what buttons of the scroll area's child are partly visible, make out how much of their surface is visible. Then I should move programmatically the child so that buttons with a visibility of 50% or more are visible.
        Otherwise, if all the buttons are of equal size, I should be able to defined a unit of movement for the scroll area somehow.

        ¹ to move the widget of the scroll area so that the child of the widget specified as an argument and a specified margin around it, is visible.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris H
          wrote on last edited by
          #4

          Yeah, I'm being dumb, that wouldn't work. I think you really just want to use a QTableView, which will let you set a scroll policy that scrolls in entire-widget increments.

          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