【问题标题】:Move items from one QListWidget to another将项目从一个 QListWidget 移动到另一个
【发布时间】:2011-06-15 09:30:35
【问题描述】:

我必须 QListWidgets,一个源列表,一个命运列表和一个按钮。每当单击按钮时,我都希望从源列表中删除选定的项目并将其插入到命运列表中。我试图source_list.removeWidgetItem(aSelectedItem) 但这甚至没有做任何事情。 :(我做错了什么?之后我需要以某种方式更新列表吗?

【问题讨论】:

    标签: python qt pyqt qlistwidget


    【解决方案1】:

    takeItem 将从 source_list 中获取项目并为您提供指向它的指针,您可以使用它来将其附加到目标列表中。比如:

    source_list = new QListWidget();
    dest_list = new QListWidget();
    new QListWidgetItem(tr("Oak"), source_list);
    new QListWidgetItem(tr("Birch"), source_list);
    connect(source_list, SIGNAL(clicked(QModelIndex)), this, SLOT(swapEntry(QModelIndex)));
    
    
    void MyWidget::swapEntry(QModelIndex index)
    {
        dest_list->insertItem(dest_list->count(), source_list->takeItem(index.row()));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 2011-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多