[英]How to respond to clicking on list items in a list view in qml, C++ qt, in Blackberry 10 Cascades
I am trying to figure out how to be able to click on an item on a list in Blackberry. 我试图弄清楚如何能够点击Blackberry列表中的项目。 I'm using QML, C++, QT, and Blackberry 10 Cascades.
我正在使用QML,C ++,QT和Blackberry 10 Cascades。 I had the list view implemented, then I tried to make it so that you could click on an item on the list by looking at this Twitter Timeline example (btw - I was not able to run the example).
我已经实现了列表视图,然后我尝试通过查看此Twitter时间轴示例(btw - 我无法运行该示例)来点击列表中的项目。
What I'm doing isn't working. 我正在做的不行。 When I call listView_->setListItemManager(new CustomerListItemManager(customerListContainer_)), it causes the list view to be blank (before I added that code, the list view showed up).
当我调用listView _-> setListItemManager(new CustomerListItemManager(customerListContainer_))时,它会导致列表视图为空(在我添加该代码之前,列表视图显示)。
So basically how to get the ability to click on an item on the list and have it respond work. 所以基本上如何能够点击列表上的项目并让它响应工作。
Anyway - here is the relevant code of what I have tried so far: 无论如何 - 这是我到目前为止所尝试的相关代码:
Container {
id: customersListContainer
objectName: "customersListContainer"
ListView {
id: customersList
objectName: "customersList"
listItemComponents: [
ListItemComponent {
type: "item"
Container {
HeaderListItem {
title: ListItemData.firstName + " " + ListItemData.lastName
}
StandardListItem {
title: ListItemData.officePhone + "\t" + ListItemData.cellPhone
description: ListItemData.email
}
]
}
}
CustomerListItemManager.cpp: CustomerListItemManager.cpp:
CustomerListItemManager::CustomerListItemManager() {}
CustomerListItemManager::~CustomerListItemManager() {}
VisualNode *CustomerListItemManager::createItem(ListView *list, const QString &type)
{
//the CustomerList::getInstance()->customerListContainer returns the customersListContainer (see the qml code above)
//
return new CustomerItem(CustomerList::getInstance()->customerListContainer());
}
void CustomerListItemManager::updateItem(ListView *list, VisualNode *control, const QString &type, const QVariantList &indexPath, const QVariant &data)
{
QObject* obj = qvariant_cast<QObject *>(data);
CustomerData* customer = qobject_cast<CustomerData *>(obj);
}
CustomerItem.cpp: CustomerItem.cpp:
CustomerItem::CustomerItem(Container *parent) : CustomControl(parent) {}
CustomerItem::~CustomerItem() {}
void CustomerItem::updateItem(const QString text, QDateTime date) {}
void CustomerItem::select(bool select) {
// Is this where you handle the response to clicking on an item on the list???
//
if (select) qDebug() << "item selected";
else;
}
void CustomerItem::reset(bool selected, bool activated) {
select(selected);
}
void CustomerItem::activate(bool activate) { Q_UNUSED(activate); }
Populating a list in another file: 填充另一个文件中的列表:
for (int i = 0; i < customers->length(); ++i) {
groupDataModel_.insert(customers->at(i)
}
listView_->setDataModel(&groupDataModel_);
//the customerListContainer_ is the customersListContainer (see the qml code above)
//
listView_->setListItemManager(new ListItemManager(customerListContainer_);
I've had this problem before. 我以前遇到过这个问题。 Basically, from a ListItemComponent, you cannot directly interact with external elements using their id for instance...
基本上,从ListItemComponent,你不能使用他们的id直接与外部元素交互...
I don't know exactly what you want to do but here are the two solutions I have that may help you : 我不知道你想要做什么,但这里有两个我可以帮助你的解决方案:
1) Using the signal "onTriggered" that is emitted when a element of you list is clicked. 1)使用单击列表元素时发出的信号“onTriggered”。 Here is a QML example :
这是一个QML示例:
onTriggered: {
console.log("onTriggered");
// Retrieve the selected item
var chosenItem = dataModel.data(indexPath);
// Bind with C++ using a Q_INVOQUABLE method
controller.launchItem(chosenItem);
}
2) In the case of selecting an element within the ListItemComponent, you can use an intermediary function. 2)在ListItemComponent中选择元素的情况下,您可以使用中间函数。 For instance, from your ListItemComponent QML definition, you can call :
例如,从ListItemComponent QML定义中,您可以调用:
// Load additional comments
ListItem.view.launchAdditionalCommentButtonPressedAction();
And then add the function to your ListView in your QML file : 然后将该函数添加到QML文件中的ListView:
function launchAdditionalButtonPressedAction() {
// Bind with C++ using a Q_INVOQUABLE method
controller.additionalButtonPressed();
}
I'm not sure this is exactly what you are looking for but I hope this helps. 我不确定这正是你想要的,但我希望这会有所帮助。
On the declaration of the ListView use the onTriggered event as the following 在ListView的声明中使用onTriggered事件如下
onTriggered: {
var selectedItem = dataModel.data(indexPath);
// do something with the selected item
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.