我正在尝试将一个项目添加到 QListWidget,选择该项目,然后开始编辑新项目。
该项目被添加,它被选中,但该行没有被带入 QLineEdit,或者它试图使用的任何东西。
这是我的小部件的代码,在“m_addButton”的连接下有相关代码:
Sequencer::Sequencer(QWidget* parent) :
QWidget(parent)
{
m_list = new QListWidget();
m_addButton = new QPushButton("Add Step");
m_removeButton = new QPushButton("Remove Step");
connect(m_addButton, &QPushButton::clicked, this, [&]()
{
m_list->addItem(""); // This part works,
m_list->setCurrentItem(m_list->item(m_list->count() - 1)); // This part works...
m_list->editItem(m_list->currentItem()); // This part puts out "edit: editing failed" into the console.
});
connect(m_removeButton, &QPushButton::clicked, this, [&]()
{
if (!m_list->selectedItems().isEmpty())
{
qDeleteAll(m_list->selectedItems());
}
});
QHBoxLayout* hLayout = new QHBoxLayout();
hLayout->addStretch();
hLayout->addWidget(m_addButton);
hLayout->addWidget(m_removeButton);
QVBoxLayout* vLayout = new QVBoxLayout();
vLayout->addWidget(m_list);
vLayout->addLayout(hLayout);
setLayout(vLayout);
}