简体   繁体   English

如何响应在Blackberry 10 Cascades中的qml,C ++ qt列表视图中单击列表项

[英]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.

相关问题 如何在Blackberry Cascades,QML和C ++,QT的列表视图中获取Web视图 - How do I get a web view in a list view in Blackberry Cascades, QML & C++, QT Blackberry 10 Cascades qml(C ++和QT)中的布局存在问题 - Having an issue with the layouts in Blackberry 10 Cascades, qml (C++ & QT) 在Blackberry Cascades 10(C ++,Qt,QML)中,如何调用填充了字段的电子邮件客户端? - In Blackberry Cascades 10 (C++, Qt, QML), how do I invoke an email client with the fields populated? 如何在Blackberry Cascades QML和QT中点击列表项组件 - How to tap on a list item component in Blackberry Cascades qml and qt 尝试将QGeoSearchReply的结果添加到Blackberry 10级联(C ++,QT和QML)中的maps :: DataProvider中 - Trying to add the result of a QGeoSearchReply to a maps::DataProvider in Blackberry 10 Cascades (C++, QT & QML) 我的Blackberry 10 Cascades(C ++,Qt和QML)示例应用程序在启动时崩溃,并出现以下错误 - My Blackberry 10 Cascades (C++, Qt & QML) sample app is crashing on startup with the following error 如何使用Cascades,Blackberry 10中的Qt / QML / C ++从另一个qml文件更改一个qml文件中的标签文本? - How do I change the label text in one qml file from another qml file using Qt/QML/C++ in Cascades, Blackberry 10? 如何在C++、Qt、QML、Blackberry 10 Cascades Beta 3 SDK中制作图表/图形(如折线图、条形图、圆形图)等? - How to make charts/graphs (such as line graphs, bar graphs, circle graphs), etc. in C++, Qt, QML, Blackberry 10 Cascades Beta 3 SDK? 使XML数据在C ++的Blackberry 10 Cascades QML中的listItemComponents中显示 - Make XML data show in listItemComponents in Blackberry 10 Cascades QML from C++ 在QML / QT 5.7中的C ++列表中添加和删除项目 - Adding and removing items from a C++ list in QML/QT 5.7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM