Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Customising ScrollView scroll bars
Forum Updated to NodeBB v4.3 + New Features

Customising ScrollView scroll bars

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 494 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.
  • B Offline
    B Offline
    Bob64
    wrote on last edited by Bob64
    #1

    I made a custom ScrollBar, mainly changing the contentItem to be bigger than the default one and changing some of the colours. This worked fine in the context I first used it but then I tried to replace the scroll bars with it in an existing ScrollView-based component (wrapping a TextArea).

    The documentation suggests that one can customise the scroll bars via the attached properties, thus:

    ScrollView {
        ...
        ScrollBar.horizontal: ScrollBar { ... }
        ScrollBar.vertical: ScrollBar {...}
    }
    

    so I initially tried assigning my custom scroll bar here. This worked for the horizontal but not the vertical scrollbar. Although both were visible and the correct size, I could not 'grab' the vertical bar and the expected colour change on pressed did not occur.

    Inspecting in GammaRay, I see that the ScrollView actually has four scroll bars attached. I presume that these are the two original attached bars plus the two I have assigned.

    I have found two approaches that seem to work but I don't know which is 'better' or even if there is a more correct way to do this:

    • Assign an instance of my scrollbar to each of the ScrollBar.horizontal and ScrollBar.vertical attached properties as I tried before, but set their z to 1.
    • Don't try to replace the attached scrollbars but just replace their content items with that of my custom ScrollBar. i.e, set ScrollBar.vertical.contentItem, etc.

    I do not have a good mental model of how attached properties work and what is allowed and what isn't. Certainly, I think the documentation could be clearer about what is going on though because it does imply that one can simply assign a new ScrollBar to the attached properties.

    Is anyone able to offer any advice or explanation here please?

    K 1 Reply Last reply
    0
    • B Bob64

      I made a custom ScrollBar, mainly changing the contentItem to be bigger than the default one and changing some of the colours. This worked fine in the context I first used it but then I tried to replace the scroll bars with it in an existing ScrollView-based component (wrapping a TextArea).

      The documentation suggests that one can customise the scroll bars via the attached properties, thus:

      ScrollView {
          ...
          ScrollBar.horizontal: ScrollBar { ... }
          ScrollBar.vertical: ScrollBar {...}
      }
      

      so I initially tried assigning my custom scroll bar here. This worked for the horizontal but not the vertical scrollbar. Although both were visible and the correct size, I could not 'grab' the vertical bar and the expected colour change on pressed did not occur.

      Inspecting in GammaRay, I see that the ScrollView actually has four scroll bars attached. I presume that these are the two original attached bars plus the two I have assigned.

      I have found two approaches that seem to work but I don't know which is 'better' or even if there is a more correct way to do this:

      • Assign an instance of my scrollbar to each of the ScrollBar.horizontal and ScrollBar.vertical attached properties as I tried before, but set their z to 1.
      • Don't try to replace the attached scrollbars but just replace their content items with that of my custom ScrollBar. i.e, set ScrollBar.vertical.contentItem, etc.

      I do not have a good mental model of how attached properties work and what is allowed and what isn't. Certainly, I think the documentation could be clearer about what is going on though because it does imply that one can simply assign a new ScrollBar to the attached properties.

      Is anyone able to offer any advice or explanation here please?

      K Offline
      K Offline
      Kamichanw
      wrote on last edited by
      #2

      @Bob64 ScrollBar of ScrollView is a piece of junk, I would advise you to implement your own ScrollView

      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