ワンクリックで編集
使用しているビューで mousePressEvent を再実装できます
void YourView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
QModelIndex index = indexAt(event->pos());
if (index.column() == 0) { // column you want to use for one click
edit(index);
}
}
QTreeView::mousePressEvent(event);
}
編集時に QCombobox を拡張 QItemDelegate
のサブクラスに setEditorData を実装し、最後に showPopup を呼び出す必要があります。
しかし、いくつかの予期しない動作があります。マウスがその領域を離れると、QComboBox は消えます。しかし、私にとっては利点です。シングルクリックとリリースで別のアイテムを選択できます。
void IconDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
Q_UNUSED(index);
QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
// Add data
comboBox->addItem(QIcon(":/icons/information16.png"), "info");
comboBox->addItem(QIcon(":/icons/warning16.png"), "warning");
comboBox->addItem(QIcon(":/icons/send16.png"), "send");
comboBox->addItem(QIcon(":/icons/select16.png"), "select");
comboBox->showPopup(); // <<<< Show popup here
}
一緒にそれは速い方法で動作します。クリックしたままにしてアイテムを選択し、リリース時にデータをコミットします(ワンクリックしてリリースするだけです) 。
クリックして展開されたqcomboboxを表示し、次にクリックして選択/非表示にする場合、今のところ解決策がわかりません。