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.8k 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
    sudarshand
    wrote on 6 May 2021, 06:15 last edited by
    #1

    How can I add horizontal scroll bar in qml table view for specific columns ? (e.g. I need horizontal scroll bar from column 3 to column 7 and I have total 11 columns in my table view). I have already implemented customize columns using delegate chooser component with the help of adding roles in C++ QAbstractTableModel Class.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sudarshand
      wrote on 11 May 2021, 05:04 last edited by
      #2

      @shawnrutledge can you please help me in this implementation? I am seeking for any idea or hint to implement this

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fcarney
        wrote on 11 May 2021, 16:29 last edited by
        #3
        property bool enableScrollbar: column >= 3 && column <= 7
        

        Use this boolean to enable scrollbar for that cell.

        C++ is a perfectly valid school of magic.

        S 1 Reply Last reply 12 May 2021, 05:29
        0
        • F fcarney
          11 May 2021, 16:29
          property bool enableScrollbar: column >= 3 && column <= 7
          

          Use this boolean to enable scrollbar for that cell.

          S Offline
          S Offline
          sudarshand
          wrote on 12 May 2021, 05:29 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 ?

          F 1 Reply Last reply 12 May 2021, 14:07
          0
          • S sudarshand
            12 May 2021, 05:29

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

            F Offline
            F Offline
            fcarney
            wrote on 12 May 2021, 14:07 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.

            S 1 Reply Last reply 17 May 2021, 04:12
            0
            • F fcarney
              12 May 2021, 14:07

              @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

              S Offline
              S Offline
              sudarshand
              wrote on 17 May 2021, 04:12 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
              • F Offline
                F Offline
                fcarney
                wrote on 17 May 2021, 15:58 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
                • V Offline
                  V Offline
                  VRonin
                  wrote on 17 May 2021, 16:06 last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sudarshand
                    wrote on 18 May 2021, 13:14 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
                    • F Offline
                      F Offline
                      fcarney
                      wrote on 18 May 2021, 14:19 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.

                      S 1 Reply Last reply 19 May 2021, 05:10
                      0
                      • F Offline
                        F Offline
                        fcarney
                        wrote on 18 May 2021, 14:20 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
                        • F fcarney
                          18 May 2021, 14:19

                          @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
                              }
                          }
                          
                          S Offline
                          S Offline
                          sudarshand
                          wrote on 19 May 2021, 05:10 last edited by
                          #12

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

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            fcarney
                            wrote on 19 May 2021, 14:23 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
                            • S Offline
                              S Offline
                              sudarshand
                              wrote on 4 Jun 2021, 14:15 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