0
votes

I am using TableView QML component, where each column width is set to the table total width divided by number of columns. This introduces some fraction parts and in result, a horizontal scrollbar is almost always visible in the bottom.

But I don't want to disable scrollbar as I have ability of changing column width and because of that scrollbar may be needed. So my problem is about initial showing of this TableView component. I want to get rid of that scrollbar when component is shown first time, but don't disable it for future usage.

I am new to QML and don't know all aspects of it, but solution that came to me is to set width of each column as I do, then for the last one get sum of all previous columns and set it's width to parent.width - that sum. Can you please help me to understand how can I implement this using QML?

1

1 Answers

0
votes

columnWidthProvider is calculated once at adding column. I cant reproduce your bug with this. contentWidth become same as width

    TableView {
        id: table
        anchors.fill: parent

        columnWidthProvider: function (column) {
            console.log(parent.width , columns, parent.width / columns)
            // wdth is 0 here
            return parent.width / columns
        }

        ScrollBar.horizontal: ScrollBar {
            policy: ScrollBar.AsNeeded 
        }

//....
    }

But i had same issue in another view. Solution was:

Flickable {

    id:view

    ScrollBar.horizontal: ScrollBar {
        policy: (view.width - view.contentWidth < -3) ? 
            ScrollBar.AlwaysOff : ScrollBar.AsNeeded}

    }
}