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.3k 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on 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...

    JoeCFDJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

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

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on 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: 
                  }
      
      mzimmersM 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @mzimmers
        This is what I did

                    // Gutter/Trough
                    background: Rectangle {
                        id:  gutter
                        implicitWidth: 
                        color: 
                    }
        
                    // Scroll Thumb
                    contentItem: Rectangle {
                        id: thumb
                        implicitWidth: 
                        radius: 
                        color: 
                    }
        
        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on 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.

        JoeCFDJ 1 Reply Last reply
        0
        • mzimmersM mzimmers

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

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on 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"
                          }
                      }
                  }
              }
          }
          
          mzimmersM 1 Reply Last reply
          1
          • JoeCFDJ JoeCFD

            @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"
                            }
                        }
                    }
                }
            }
            
            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on 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...

            JoeCFDJ 1 Reply Last reply
            0
            • mzimmersM mzimmers

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

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

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

              mzimmersM 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

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

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on 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
                • mzimmersM mzimmers has marked this topic as solved on

                • Login

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