Is it possible to modify header/footer of ListView.???
-
Hello,
Is it possible to modify the header/footer of the ListView.??
say I have a header and footer components, each having a Text in it...
Now upon and mouse click I want to change the text of header and footer. -
Hello.
I do not quite understand your question. A QListView does not display a header.
But it sounds like you might want to do something like connecting the signal
@
signal:
void clicked(const QModelIndex & index))
@of your ListView to some function, that updates the element if it is a header or footer.
-
I think this is a bit tricky. The QListView or QTableView is just a "view" control. All it's data, inclduing the text for the header, is taken from the QAbstractItemModel that the view is connected to. The model doesn't know anything about the view(s). You may connect a slot to the clicked() signal of the view and, inside that slot, react on the click-event by modifying the model accordingly. Your model would need some suitable "setter" method for this purpose. But keep in mind that an arbitrary number of views may be connected to the same model!
-
I am working in QML...
where I have ListView like,@
ListView {
header : headerComponent
footer : footerComponent
model : inputModel
delegate : outputModel
}Component {
id : headerComponent
Text {
}
}
@ -
Connecting to signals also works in QML, but I am not sure how you would have to write that. You might get better answers if you asked your question in the Qt Quick forum; http://qt-project.org/forums/viewforum/12/ .
-
I moved this one as suggested.
But i still don't understand what you want exactly. Can you elaborate?
Eg clicking on an item, you can get an ID and use that to get data from the model and set it as text in the header component. Is that what you want?
For QML the same advise from MuldeR about model/view is important.
-
[quote author="mkuettler" date="1337976569"]Connecting to signals also works in QML, but I am not sure how you would have to write that. You might get better answers if you asked your question in the Qt Quick forum; http://qt-project.org/forums/viewforum/12/ .[/quote]
"You can use Connections element":http://qt-project.org/doc/qt-4.8/qml-connections.html
It is also possible to use C++ combined with QML. "Here is a good start":http://qt-project.org/wiki/Introduction_to_Qt_Quick_for_Cpp_developers -
Maybe u can try:
@
ListView{
id: listView
property Item headerItem
header: Text{
id: headerComponent
text: "Header"
Component.onCompleted: listView.headerItem = headerComponent
}
}MouseArea{
onClicked: listView.headerItem.text = "ABC"
}
@ -
I doubt about this to work... May be it is not possible to alter the header footer components.
-
First I thought it is possible but it seems that header or footer element id is not recognized properly. Here's the modified code that worked for me.
Main point is using a universal scoped variable@import QtQuick 1.1
import com.nokia.symbian 1.1Page {
property string buttonText : "OK" ListView { id: list_view1 anchors.fill: parent delegate: Item { x: 5 height: 40 Row { id: row1 spacing: 10 Rectangle { width: 40 height: 40 color: colorCode } Text { text: name anchors.verticalCenter: parent.verticalCenter font.bold: true color: "white" } Button { id: button1 x: 272 y: 0 text: "Button" onClicked : buttonText = model.name } } } model: ListModel { ListElement { name: "Grey" colorCode: "grey" } ListElement { name: "Red" colorCode: "red" } } header: ToolButton { id : button text: buttonText } Button { id: button1x x: 272 y: 0 text: "Button" onClicked: buttonText = "It works" } }
}
@