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. How can I add horizontal scroll bar for specific columns in QML table view component?
Forum Updated to NodeBB v4.3 + New Features

How can I add horizontal scroll bar for specific columns in QML table view component?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
14 Posts 3 Posters 1.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.
  • fcarneyF fcarney
    property bool enableScrollbar: column >= 3 && column <= 7
    

    Use this boolean to enable scrollbar for that cell.

    sudarshandS Offline
    sudarshandS Offline
    sudarshand
    wrote on last edited by
    #4

    @fcarney said in How can I add horizontal scroll bar for specific columns in QML table view component?:

    enable

    Where and how can I apply this property to QML table view ?

    fcarneyF 1 Reply Last reply
    0
    • sudarshandS sudarshand

      @fcarney said in How can I add horizontal scroll bar for specific columns in QML table view component?:

      enable

      Where and how can I apply this property to QML table view ?

      fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #5

      @sudarshand said in How can I add horizontal scroll bar for specific columns in QML table view component?:

      Where and how can I apply this property to QML table view ?

      https://doc.qt.io/qt-5/qml-qtquick-controls2-scrollbar.html

      C++ is a perfectly valid school of magic.

      sudarshandS 1 Reply Last reply
      0
      • fcarneyF fcarney

        @sudarshand said in How can I add horizontal scroll bar for specific columns in QML table view component?:

        Where and how can I apply this property to QML table view ?

        https://doc.qt.io/qt-5/qml-qtquick-controls2-scrollbar.html

        sudarshandS Offline
        sudarshandS Offline
        sudarshand
        wrote on last edited by
        #6

        @fcarney I am not able to achieve what I want from these inputs...., I am not able to apply this in my QML table view implementation.

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by fcarney
          #7

          Create a minimal example code for us to look at. I cannot tell what you are doing.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #8
            This post is deleted!
            1 Reply Last reply
            0
            • sudarshandS Offline
              sudarshandS Offline
              sudarshand
              wrote on last edited by
              #9

              Hello @fcarney please refer following QML implementation , tableviewmodel is my C++ model inherited from QAbstractTableModel class having 11 columns and some rows. I want horizontal scrolling for column 3 to 7 only and all other columns should be freeze.
              Because of this line i.e. ScrollBar.horizontal: ScrollBar{} , I am getting horizontal scroll bar for all the columns.

              TableView {
              id: tableview
              anchors.fill: parent
              columnSpacing: 1
              rowSpacing: 1
              columnWidthProvider: function(col) {
              if( 0 === col || 1 === col || 10 === col)
              return 40
              else if(3 === col)
              return 80
              else
              return 60
              }
              rowHeightProvider: function(){
              return 60
              }
              clip: true
              ScrollBar.horizontal: ScrollBar{}
              ScrollBar.vertical: ScrollBar{}
              model: tableviewmodel

              delegate: Rectangle {
                  Text {
                      text: roletabledata
                  }
              }
              

              }

              1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by fcarney
                #10

                @fcarney said in How can I add horizontal scroll bar for specific columns in QML table view component?:

                property bool enableScrollbar: column >= 3 && column <= 7

                TableView {
                    id: tableview
                    property bool enableScrollbar: column >= 3 && column <= 7
                ...
                    ScrollBar.horizontal: ScrollBar{
                        visible:  tableview.enableScrollbar  // not sure if you need to use enable or not
                    }
                }
                

                C++ is a perfectly valid school of magic.

                sudarshandS 1 Reply Last reply
                0
                • fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on last edited by
                  #11

                  @fcarney said in How can I add horizontal scroll bar for specific columns in QML table view component?:

                  ScrollBar.horizontal: ScrollBar{
                  visible: tableview.enableScrollbar // not sure if you need to use enable or not
                  }

                  Alternately:

                   ScrollBar.horizontal: tableview.enableScrollbar ? ScrollBar{} : null
                  

                  C++ is a perfectly valid school of magic.

                  1 Reply Last reply
                  0
                  • fcarneyF fcarney

                    @fcarney said in How can I add horizontal scroll bar for specific columns in QML table view component?:

                    property bool enableScrollbar: column >= 3 && column <= 7

                    TableView {
                        id: tableview
                        property bool enableScrollbar: column >= 3 && column <= 7
                    ...
                        ScrollBar.horizontal: ScrollBar{
                            visible:  tableview.enableScrollbar  // not sure if you need to use enable or not
                        }
                    }
                    
                    sudarshandS Offline
                    sudarshandS Offline
                    sudarshand
                    wrote on last edited by
                    #12

                    @fcarney for this its giving QML error that column is not defined.

                    1 Reply Last reply
                    0
                    • fcarneyF Offline
                      fcarneyF Offline
                      fcarney
                      wrote on last edited by
                      #13

                      Sorry, this should be inside the delegate:

                      TableView {
                          id: tableview
                          property bool enableScrollbar: column >= 3 && column <= 7
                      ...
                          ScrollBar.horizontal: ScrollBar{
                              visible:  tableview.enableScrollbar  // not sure if you need to use enable or not
                          }
                      }
                      
                      A reference a day helps keep the segfault away.
                      0
                      fcarney about 24 hours ago
                      
                      @fcarney said in How can I add horizontal scroll bar for specific columns in QML table view component?:
                      
                          ScrollBar.horizontal: ScrollBar{
                          visible: tableview.enableScrollbar // not sure if you need to use enable or not
                          }
                      
                      Alternately:
                      
                       ScrollBar.horizontal: tableview.enableScrollbar ? ScrollBar{} : null
                      
                      A reference a day helps keep the segfault away.
                      0
                      sudarshand about 9 hours ago
                      
                      @fcarney for this its giving QML error that column is not defined.
                      
                          0
                      
                      12
                      Posts
                      84
                      Views
                       
                      
                      @fcarney said in How can I add horizontal scroll bar for specific columns in QML table view component?:
                      
                          property bool enableScrollbar: column >= 3 && column <= 7
                      
                      TableView {
                          id: tableview
                      
                          delegate: Flickable { // some kind of flickable I think
                              property bool enableScrollbar: column >= 3 && column <= 7
                      
                              ScrollBar.horizontal: ScrollBar{
                                  visible:  tableview.enableScrollbar  // not sure if you need to use enable or not
                              }
                          }
                      }
                      
                      

                      Rectangle is not a flickable I don't think. I don't know if it will work with that.
                      Spend more time reading the docs.

                      C++ is a perfectly valid school of magic.

                      1 Reply Last reply
                      0
                      • sudarshandS Offline
                        sudarshandS Offline
                        sudarshand
                        wrote on last edited by
                        #14

                        I am able to achieve it, using QML vertical header view component of Qt version 5.15.4.

                        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