How to use other items in a view?



  • Hi,

    I'm new to QtQuick but have already done a lot with QtQwidgets and the standard views like QTableView. In our current project we still use QTableView to display appointments. When an appointment starts or ends beyond the current shown time part, arrows at the end of the rows indicate that this appointment does not end here.

    So when the user hovers these arrows a tool tip shows the time when the appointment starts or ends. If the user is clicking on the arrow the time part shown in the view shifts a time step to the wanted direction.

    It was not easy to implement these arrows, since QTableView seems not to offer a way to add QWidgets to table cells without delegating. But delegating only works if the user wants to edit something. But the arrows have to be shown when the model of the QTableView was set.

    So we painted the arrows by ourselfes at the right position and implemented with QEvent the standard widget interaction functionalities we needed.

    Now I have read about QtQuick and QML and was exulted about the offered possibilities. So if I have understood QML correct you can stack "widgets" easily together? My idea was to enable the above mentioned arrows with QML. So I created a test project displaying a TableView with some rows and tried to add a button into it:

    @ListModel{
    id: testModel
    ListElement{ V1: "value1"; V2: "value2"}
    }

    TableView {
        TableViewColumn{id: col1; role: "V1"; title: "VALUE_1"; width: 100 }
        TableViewColumn{ role: "V2"; title: "VALUE_2"; width: 100 }
        model: testModel
        Button{
            text: "Button1"
        }
    }@
    

    As anticipated the button is shown in the top left corner of the table view. But how can I show this button dynamically in a row if it's needed? I tried to add a button the same way in a ListElement but the result was an error... Have you any idea how I can realise that?



  • Okay, I have found a way:

    @TableView {
    TableViewColumn{id: col1; role: "V1"; title: "VALUE_1"; width: 100 }
    TableViewColumn{ role: "V2"; title: "VALUE_2"; width: 100 }
    model: testModel

        itemDelegate:Item{
    
            Button{
                visible: styleData.column === 0
                id: arrow
                tooltip: "Left"
            }
            Text {
                anchors.left: arrow.right
                text: styleData.value
            }
        }
    
    }@
    

    I suppose the itemDelegate in QML is different from the delegate-functionality in QtWidget because in QML there is no user action like clicking needed before the delegation widget will be drawed and usable, right? Or did I oversee a property with the QtWidgets which enables also an immediately using of the delegate widget?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.