Nmaster88
Nmaster88

Reputation: 1585

After styling TableView Scroll i get a warning in QML

I'm styling the handler in a TableView Component using the following code:

TableView {
    style: ScrollViewStyle{
        handle: Rectangle {
            implicitWidth: globals.scrollBar.handlerWidth
            implicitHeight: globals.scrollBar.handlerWidth
            color:  globals.scrollBar.handlerColor
        }
    }
}

The properties are:

property var scrollBar: QtObject {
    property int handlerWidth: 14
    property color handlerColor: "#6b6b6b"
}

I tried switching int and color to var but i still have the same problem.

Globals are defined on main, like this:

Globals {
    id: globals
}

Now i'm getting a lot of warnings in QT

file:///C:/Qt/5.11.1/mingw53_32/qml/QtQuick/Controls/Private/BasicTableView.qml:393:48: Unable to assign [undefined] to bool
file:///C:/Qt/5.11.1/mingw53_32/qml/QtQuick/Controls/Private/BasicTableView.qml:97:38: Unable to assign [undefined] to QQmlComponent*
file:///C:/Qt/5.11.1/mingw53_32/qml/QtQuick/Controls/Private/BasicTableView.qml:461:20: Unable to assign [undefined] to QColor

What am i missing?

A minimal functional example creating an empty qt (5.12) application with qml

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls 1.4
    import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.1

ApplicationWindow {
    id: window
    title: "Stack"
    visible: true
    width: 1400
    ListModel {
        id: libraryModel
        ListElement {
            title: "A Masterpiece"
            author: "Gabriel"
        }
        ListElement {
            title: "Brilliance"
            author: "Jens"
        }
        ListElement {
            title: "Outstanding"
            author: "Frederik"
        }
    }

    Page {
        id: page
        anchors.fill: parent
        background: { color:"black" }
        TableView{
            style: ScrollViewStyle{//TODO:  ScrollViewStyle is giving a lot of warnings
                handle: Rectangle {
                    implicitWidth: 15
                    implicitHeight: 15
                    color:  "#000000"
                }
                minimumHandleLength: 30
            }
            anchors.fill:parent
            TableViewColumn {
                role: "title"
                title: "Title"
                width: 100
            }
            TableViewColumn {
                role: "author"
                title: "Author"
                width: 200
            }
            model: libraryModel
            itemDelegate: Text
            {
              text: styleData.value
              elide: Text.ElideRight
            }
        }
    }
}

Maybe the error/warning is related to imcompatibly imports?

Upvotes: 1

Views: 653

Answers (1)

eyllanesc
eyllanesc

Reputation: 243965

If you use TableView then you must use TableViewStyle instead of ScrollViewStyle. and you can continue using the same properties since TableViewStyle inherits from ScrollViewStyle:

style: TableViewStyle{
    handle: Rectangle {
        implicitWidth: 15
        implicitHeight: 15
        color:  "#000000"
    }
    minimumHandleLength: 30
}

Remove the following line of code since background expects a Component, but it is also unnecessary since TableView will occupy the entire Page:

background: { color:"black" }

Upvotes: 1

Related Questions