c++ - 如何在 Blackberry 10 Cascades 的 qml、C++ qt 中响应单击 ListView 中的列表项

标签 c++ qt listview qml blackberry-10

我正在尝试弄清楚如何能够单击黑莓列表中的项目。我正在使用 QML、C++、QT 和 Blackberry 10 Cascades。我实现了 ListView ,然后我尝试实现它,以便您可以通过查看此 Twitter 时间线示例来单击列表中的项目(顺便说一句 - 我无法运行该示例)。

我正在做的是行不通的。当我调用 listView_->setListItemManager(new CustomerListItemManager(customerListContainer_)) 时,它导致 ListView 为空白(在我添加该代码之前, ListView 出现了)。

那么基本上如何获得单击列表中的项目并让它响应的能力。

无论如何 - 这是我到目前为止所尝试的相关代码:

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::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);
}

客户项目.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); }

在另一个文件中填充列表:

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_);

最佳答案

我以前遇到过这个问题。 基本上,在 ListItemComponent 中,您不能使用外部元素的 id 直接与外部元素交互...

我不知道你到底想做什么,但这里有两个可能对你有帮助的解决方案:

1) 使用单击列表中的元素时发出的信号“onTriggered”。这是一个 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) 在选择 ListItemComponent 中的元素的情况下,您可以使用中间函数。 例如,根据您的 ListItemComponent QML 定义,您可以调用:

// Load additional comments
ListItem.view.launchAdditionalCommentButtonPressedAction();

然后将函数添加到 QML 文件中的 ListView 中:

function launchAdditionalButtonPressedAction() {
    // Bind with C++ using a Q_INVOQUABLE method
    controller.additionalButtonPressed();
}

我不确定这是否正是您要找的,但我希望这对您有所帮助。

关于c++ - 如何在 Blackberry 10 Cascades 的 qml、C++ qt 中响应单击 ListView 中的列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12647816/

相关文章:

android - 我可以将一种布局用于 2 个 Activity 吗?

java - 将项目添加到 ListView 适配器中的特定列

android - 如何从android listview中获取选中的项目?

c++ - 找不到 Sphinx Ubuntu 14 c++ sphinx_config.h

在我的用户定义类型上使用 boost::get 的 C++ Boost::variant 错误

qt - 在实例化 QApplication 后 qDebug() 时,我丢失了 “unicodeness”

c++ - Qt 和 native 菜单

c++ - 为什么我不能用这个功能在Qt框架中打开另一个进程?

c++ - 使用 c++ ios::ate 得到错误的文件大小

c++ - 访问 vector 字段的键 - 命名空间中的枚举类或枚举?