Answer the question
In order to leave comments, you need to log in
How to connect a signal to select a model element with its own slot?
treeView = new QTreeView();
treeView->header()->hide();
treeView->setModel(treeCtrl);
QItemSelectionModel* _select;
_select = new QItemSelectionModel(treeCtrl);
treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(treeView, &QWidget::customContextMenuRequested, this, &MainForm::treeContextMenu);
connect(_select, &QItemSelectionModel::selectionChanged,
this, &MainForm::treeSelectionChanged);
void MainForm::treeSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
{
qDebug() << "selectionChanged";
QModelIndex index = selected.indexes().at(0);
propCtrl = new StatPropCtrl(&index);
}
Answer the question
In order to leave comments, you need to log in
apparently not, since it doesn’t enter the function at all, the
main thing is in the slot where the first connection enters the breakpoint, and the second one doesn’t
, it doesn’t work either
connect(treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), SLOT(treeSelectionChanged(QModelIndex, QModelIndex)));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question