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. Customizing contentItem of ScrollBar
Forum Updated to NodeBB v4.3 + New Features

Customizing contentItem of ScrollBar

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 1.2k 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 27 Mar 2023, 15:21 last edited by
    #1

    Hi all -

    I'm trying to build a screen with the following code (unnecessary stuff removed for brevity):

    import QtQuick
    import QtQuick.Controls
    import QtQuick.Layouts
    
    import Manager
    
    ApplicationWindow {
        id: mainWindow
        width: 640
        height: 480
        visible: true
    
        ColumnLayout {
    
            // a bunch of other stuff
            
            ScrollView {
                id: scrollView
                property real scrollerWidth: 12
                Layout.preferredHeight: 200
                Layout.preferredWidth: 400
                Layout.alignment: Qt.AlignHCenter
                
                TextArea {
                    width: scrollView.width - (scrollView.scrollerWidth * 2)
                    text: manager.replyData // manager is a model
                }
                ScrollBar.vertical: ScrollBar {
                    x: scrollView.width
                    height: scrollView.availableHeight
                    policy: ScrollBar.AlwaysOn
                    contentItem: Rectangle {} // <== this line causes problems.
                }
            }
        }
    }
    

    which produces something like this (just fine):
    good.PNG
    But I want to customize the contentItem (change the color, add a radius to it, change the background). Any attempts to do so, however, produce an unresponsive ScrollBar (the content item size doesn't change, and when I hover over the ScrollBar, I get a message "Unable to assign [undefined] to int."

    Obviously, I'm missing something in the Rectangle code, but I've tried several things (height, implicitHeight, etc) and nothing seems to help. Can someone see what I'm doing wrong here?

    Thanks...

    J 1 Reply Last reply 27 Mar 2023, 15:40
    0
    • M mzimmers
      27 Mar 2023, 15:21

      Hi all -

      I'm trying to build a screen with the following code (unnecessary stuff removed for brevity):

      import QtQuick
      import QtQuick.Controls
      import QtQuick.Layouts
      
      import Manager
      
      ApplicationWindow {
          id: mainWindow
          width: 640
          height: 480
          visible: true
      
          ColumnLayout {
      
              // a bunch of other stuff
              
              ScrollView {
                  id: scrollView
                  property real scrollerWidth: 12
                  Layout.preferredHeight: 200
                  Layout.preferredWidth: 400
                  Layout.alignment: Qt.AlignHCenter
                  
                  TextArea {
                      width: scrollView.width - (scrollView.scrollerWidth * 2)
                      text: manager.replyData // manager is a model
                  }
                  ScrollBar.vertical: ScrollBar {
                      x: scrollView.width
                      height: scrollView.availableHeight
                      policy: ScrollBar.AlwaysOn
                      contentItem: Rectangle {} // <== this line causes problems.
                  }
              }
          }
      }
      

      which produces something like this (just fine):
      good.PNG
      But I want to customize the contentItem (change the color, add a radius to it, change the background). Any attempts to do so, however, produce an unresponsive ScrollBar (the content item size doesn't change, and when I hover over the ScrollBar, I get a message "Unable to assign [undefined] to int."

      Obviously, I'm missing something in the Rectangle code, but I've tried several things (height, implicitHeight, etc) and nothing seems to help. Can someone see what I'm doing wrong here?

      Thanks...

      J Offline
      J Offline
      JoeCFD
      wrote on 27 Mar 2023, 15:40 last edited by JoeCFD
      #2

      @mzimmers
      This is what I did

                  // Gutter/Trough
                  background: Rectangle {
                      id:  gutter
                      implicitWidth: 
                      color: 
                  }
      
                  // Scroll Thumb
                  contentItem: Rectangle {
                      id: thumb
                      implicitWidth: 
                      radius: 
                      color: 
                  }
      
      M 1 Reply Last reply 27 Mar 2023, 15:48
      0
      • J JoeCFD
        27 Mar 2023, 15:40

        @mzimmers
        This is what I did

                    // Gutter/Trough
                    background: Rectangle {
                        id:  gutter
                        implicitWidth: 
                        color: 
                    }
        
                    // Scroll Thumb
                    contentItem: Rectangle {
                        id: thumb
                        implicitWidth: 
                        radius: 
                        color: 
                    }
        
        M Offline
        M Offline
        mzimmers
        wrote on 27 Mar 2023, 15:48 last edited by
        #3

        @JoeCFD I've tried setting those values; it doesn't change the behavior.

        I get the impression that somehow, the ScrollBar isn't properly associated with the TextView, but I don't know how to fix it.

        J 1 Reply Last reply 27 Mar 2023, 16:14
        0
        • M mzimmers
          27 Mar 2023, 15:48

          @JoeCFD I've tried setting those values; it doesn't change the behavior.

          I get the impression that somehow, the ScrollBar isn't properly associated with the TextView, but I don't know how to fix it.

          J Offline
          J Offline
          JoeCFD
          wrote on 27 Mar 2023, 16:14 last edited by
          #4

          @mzimmers
          This code works on Ubuntu 22.04 with Qt 6,5

          import QtQuick
          import QtQuick.Controls
          import QtQuick.Layouts
          
          ApplicationWindow {
              id: mainWindow
              width: 640
              height: 480
              visible: true
          
              ColumnLayout {
          
                  // a bunch of other stuff
                  
                  ScrollView {
                      id: scrollView
                      property real scrollerWidth: 12
                      Layout.preferredHeight: 200
                      Layout.preferredWidth: 400
                      Layout.alignment: Qt.AlignHCenter
                      
                      TextArea {
                          width: scrollView.width - (scrollView.scrollerWidth * 2)
                          text: "ABBBBBB\nBBBBBBBBBBB\nBBBBBBBBB\nBBBBBBB\nBBBBBB\nBBBB\nBBBBBBBBB\nBBBB\nBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBB"
                      }
                   
                      ScrollBar.vertical: ScrollBar {
                          x: scrollView.width
                          height: scrollView.availableHeight
                          policy: ScrollBar.AlwaysOn
                          contentItem: Rectangle {
                              id: thumb
                              implicitWidth: 10
                              radius: 5
                              color: "#000000"
                          }
                      }
                  }
              }
          }
          
          M 1 Reply Last reply 27 Mar 2023, 16:20
          1
          • J JoeCFD
            27 Mar 2023, 16:14

            @mzimmers
            This code works on Ubuntu 22.04 with Qt 6,5

            import QtQuick
            import QtQuick.Controls
            import QtQuick.Layouts
            
            ApplicationWindow {
                id: mainWindow
                width: 640
                height: 480
                visible: true
            
                ColumnLayout {
            
                    // a bunch of other stuff
                    
                    ScrollView {
                        id: scrollView
                        property real scrollerWidth: 12
                        Layout.preferredHeight: 200
                        Layout.preferredWidth: 400
                        Layout.alignment: Qt.AlignHCenter
                        
                        TextArea {
                            width: scrollView.width - (scrollView.scrollerWidth * 2)
                            text: "ABBBBBB\nBBBBBBBBBBB\nBBBBBBBBB\nBBBBBBB\nBBBBBB\nBBBB\nBBBBBBBBB\nBBBB\nBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBB"
                        }
                     
                        ScrollBar.vertical: ScrollBar {
                            x: scrollView.width
                            height: scrollView.availableHeight
                            policy: ScrollBar.AlwaysOn
                            contentItem: Rectangle {
                                id: thumb
                                implicitWidth: 10
                                radius: 5
                                color: "#000000"
                            }
                        }
                    }
                }
            }
            
            M Offline
            M Offline
            mzimmers
            wrote on 27 Mar 2023, 16:20 last edited by mzimmers
            #5

            @JoeCFD wow...it absolutely does not work on Windows 10 with Qt 6.4.3.

            Amazing. I guess it's time for a bug report, but before I do, I think I'll try a few different styles. Are you using Fusion (the default for Linux)?

            EDIT:

            I just tried Fusion (on Windows) and it works fine. Sheesh...

            J 1 Reply Last reply 27 Mar 2023, 16:24
            0
            • M mzimmers
              27 Mar 2023, 16:20

              @JoeCFD wow...it absolutely does not work on Windows 10 with Qt 6.4.3.

              Amazing. I guess it's time for a bug report, but before I do, I think I'll try a few different styles. Are you using Fusion (the default for Linux)?

              EDIT:

              I just tried Fusion (on Windows) and it works fine. Sheesh...

              J Offline
              J Offline
              JoeCFD
              wrote on 27 Mar 2023, 16:24 last edited by JoeCFD
              #6

              @mzimmers I simply use command qml to test it without any C++ code.

              M 1 Reply Last reply 27 Mar 2023, 17:09
              0
              • J JoeCFD
                27 Mar 2023, 16:24

                @mzimmers I simply use command qml to test it without any C++ code.

                M Offline
                M Offline
                mzimmers
                wrote on 27 Mar 2023, 17:09 last edited by
                #7

                Update: I just installed Qt 6.6.0 and built my app. Still have the same problem, but now, I get an error:

                QML Rectangle: The current style does not support customization of this control (property: "background" item: QQuickRectangle(0x193c8278c30, parent=0x0, geometry=0,0 0x0)). Please customize a non-native style (such as Basic, Fusion, Material, etc). For more information, see: https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference
                

                Following the link, I see this note:

                Note: The macOS and Windows styles are not suitable for customizing. [...]
                

                So...I guess I won't be using the Windows style (which is entirely fine by me). So the takeaway is, if you're going to customize controls, choose one of the custom styles.

                1 Reply Last reply
                1
                • M mzimmers has marked this topic as solved on 27 Mar 2023, 17:09

                1/7

                27 Mar 2023, 15:21

                • Login

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