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. Illustration of customization of scroll bar using QtQuick.Controls 2.2.
Forum Updated to NodeBB v4.3 + New Features

Illustration of customization of scroll bar using QtQuick.Controls 2.2.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 916 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.
  • S Offline
    S Offline
    Satyakaama
    wrote on 26 Mar 2019, 04:04 last edited by
    #1

    Hi All,

    I have customized scroll bar using QtQuick.Controls 1.4 .

    But i need to port it using QtQuick.Controls 2.4 ?

    Can some one please share illustration of using property such as
    decrementControl : Component ,
    incrementControl : Component,
    scrollBarBackground : Component,
    handle : Component

    Thanks in advance

    J 1 Reply Last reply 26 Mar 2019, 05:57
    0
    • S Offline
      S Offline
      Shrinidhi Upadhyaya
      wrote on 26 Mar 2019, 05:47 last edited by
      #2

      Hi @Satyakaama , here is the sample code below, there are two scroll bars one is the default one while the other one is Customized one,have a look into it,you will get to know how to customize the background ,content item etc. There are 2 buttons which can be used to increase or decrease the scroll bar,you can select the scroll bar in the combo box.

          Row {
              anchors.horizontalCenter: parent.horizontalCenter
              spacing: 10
      
              ComboBox {
                  id: selectBarOption
                  height: 100
                  width: 100
                  model: ["Vertical Bar","Horizontal Bar"]
              }
      
              Button {
                  height: 100
                  width: 100
                  text: "Increase"
                  onClicked: {
                      if(selectBarOption.currentIndex === 0)
                          vbar.increase();
                      else
                          hbar.increase();
                  }
              }
      
              Button {
                  height: 100
                  width: 100
                  text: "Decrease"
                  onClicked: {
                      if(selectBarOption.currentIndex === 0)
                          vbar.decrease();
                      else
                          hbar.decrease();
                  }
              }
          }
      
          Rectangle {
              id: frame
              clip: true
              width: 160
              height: 160
              border.color: "black"
              anchors.centerIn: parent
      
              Text {
                  id: content
                  text: "ABC"
                  font.pixelSize: 160
                  x: -hbar.position * width
                  y: -vbar.position * height
              }
      
              //####Customized ScrollBar
              ScrollBar {
                  id: vbar
                  hoverEnabled: true
                  active: hovered || pressed
                  orientation: Qt.Vertical
                  size: frame.height / content.height
                  anchors.top: parent.top
                  anchors.right: parent.right
                  anchors.bottom: parent.bottom
      
                  background: Rectangle {
                      width: parent.width
                      height: parent.height
                      color: "dark grey"
                  }
      
                  contentItem: Rectangle {
                      implicitWidth: 6
                      implicitHeight: 10
                      radius: width / 2
                      color: vbar.pressed ? "cyan" : "light green"
                  }
              }
      
              //####Default ScrollBar
              ScrollBar {
                  id: hbar
                  hoverEnabled: true
                  active: hovered || pressed
                  orientation: Qt.Horizontal
                  size: frame.width / content.width
                  anchors.left: parent.left
                  anchors.right: parent.right
                  anchors.bottom: parent.bottom
              }
          }
      

      For more details you can have a look into the documentation:- [https://doc.qt.io/qt-5/qml-qtquick-controls2-scrollbar.html#stepSize-prop]

      Note:- Copy paste the code and try to run it,you will have a better understanding.

      Shrinidhi Upadhyaya.
      Upvote the answer(s) that helped you to solve the issue.

      S 1 Reply Last reply 28 Mar 2019, 09:14
      1
      • S Satyakaama
        26 Mar 2019, 04:04

        Hi All,

        I have customized scroll bar using QtQuick.Controls 1.4 .

        But i need to port it using QtQuick.Controls 2.4 ?

        Can some one please share illustration of using property such as
        decrementControl : Component ,
        incrementControl : Component,
        scrollBarBackground : Component,
        handle : Component

        Thanks in advance

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 26 Mar 2019, 05:57 last edited by
        #3

        hi @Satyakaama
        have you taken a look at the docs yet?
        https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-scrollbar

        That should cover everything that is possible, and not only Scrollbar ;-)


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        S 1 Reply Last reply 28 Mar 2019, 09:14
        1
        • S Shrinidhi Upadhyaya
          26 Mar 2019, 05:47

          Hi @Satyakaama , here is the sample code below, there are two scroll bars one is the default one while the other one is Customized one,have a look into it,you will get to know how to customize the background ,content item etc. There are 2 buttons which can be used to increase or decrease the scroll bar,you can select the scroll bar in the combo box.

              Row {
                  anchors.horizontalCenter: parent.horizontalCenter
                  spacing: 10
          
                  ComboBox {
                      id: selectBarOption
                      height: 100
                      width: 100
                      model: ["Vertical Bar","Horizontal Bar"]
                  }
          
                  Button {
                      height: 100
                      width: 100
                      text: "Increase"
                      onClicked: {
                          if(selectBarOption.currentIndex === 0)
                              vbar.increase();
                          else
                              hbar.increase();
                      }
                  }
          
                  Button {
                      height: 100
                      width: 100
                      text: "Decrease"
                      onClicked: {
                          if(selectBarOption.currentIndex === 0)
                              vbar.decrease();
                          else
                              hbar.decrease();
                      }
                  }
              }
          
              Rectangle {
                  id: frame
                  clip: true
                  width: 160
                  height: 160
                  border.color: "black"
                  anchors.centerIn: parent
          
                  Text {
                      id: content
                      text: "ABC"
                      font.pixelSize: 160
                      x: -hbar.position * width
                      y: -vbar.position * height
                  }
          
                  //####Customized ScrollBar
                  ScrollBar {
                      id: vbar
                      hoverEnabled: true
                      active: hovered || pressed
                      orientation: Qt.Vertical
                      size: frame.height / content.height
                      anchors.top: parent.top
                      anchors.right: parent.right
                      anchors.bottom: parent.bottom
          
                      background: Rectangle {
                          width: parent.width
                          height: parent.height
                          color: "dark grey"
                      }
          
                      contentItem: Rectangle {
                          implicitWidth: 6
                          implicitHeight: 10
                          radius: width / 2
                          color: vbar.pressed ? "cyan" : "light green"
                      }
                  }
          
                  //####Default ScrollBar
                  ScrollBar {
                      id: hbar
                      hoverEnabled: true
                      active: hovered || pressed
                      orientation: Qt.Horizontal
                      size: frame.width / content.width
                      anchors.left: parent.left
                      anchors.right: parent.right
                      anchors.bottom: parent.bottom
                  }
              }
          

          For more details you can have a look into the documentation:- [https://doc.qt.io/qt-5/qml-qtquick-controls2-scrollbar.html#stepSize-prop]

          Note:- Copy paste the code and try to run it,you will have a better understanding.

          S Offline
          S Offline
          Satyakaama
          wrote on 28 Mar 2019, 09:14 last edited by
          #4

          @Shrinidhi-Upadhyaya Thanks a lot . It helped.

          1 Reply Last reply
          0
          • J J.Hilk
            26 Mar 2019, 05:57

            hi @Satyakaama
            have you taken a look at the docs yet?
            https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-scrollbar

            That should cover everything that is possible, and not only Scrollbar ;-)

            S Offline
            S Offline
            Satyakaama
            wrote on 28 Mar 2019, 09:14 last edited by
            #5

            @J.Hilk Thanks a lot !!!

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Satyakaama
              wrote on 28 Mar 2019, 09:15 last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0

              4/6

              28 Mar 2019, 09:14

              • Login

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