Unsolved Connecting QPushButton to QListWidget
-
@SGaist Thanks for the reply.
After retrieving the selected item, is there a way to emit a signal that it has been double clicked ?
My goal is to provide aQPushButton
that will perform the functionality of double clicking an item in theQListWidget
. -
Well, you should rather have a slot connected to the QListWidget::itemDoubleClicked signal and then call the same function from the slot connect to your QPushButton::clicked signal.
-
@SGaist Yes that was what I was going for.
Now consider I am usingQAbstractItemView::doubleClicked(const QModelIndex & index)
.
I looked for a way to get theQModelIndex
in myQPushButton
SLOT().
So initially I thought I will callQListWidget::currentItem()
and thenQListWidget::indexFromItem(QListWidgetItem * item)
.
This would be ideal but that last method is protected and I cannot call it.Any idea ?
-
@walle19 said in Connecting QPushButton to QListWidget:
Any idea ?
QListWidget has a signal QListWidget::itemDoubleClicked(QListWidgetItem*).
-
@Christian-Ehrlicher Thanks for your reply. This method is good,
But Is there a way to retrieve theQModelIndex
of theQListWidgetItem
? -
@walle19 Use indexFromItem() method:
QModelIndex index = listwidget->indexFromItem(item);
-
@eyllanesc isn't this a protected method ?
I am getting a compile error when compiling it......../Qt-4.7.1/include/QtGui/qlistwidget.h:287:17: error: ‘QModelIndex QListWidget::indexFromItem(QListWidgetItem*) const’ is protected QModelIndex indexFromItem(QListWidgetItem *item) const
-
Why do you need the index at all? Either use a QListWidget and work only with QListWidgetItems or use a QListView and use an own model but do not mix both.
Also why are you using Qt4? -
@Christian-Ehrlicher Hi,
Using QT4 is a constraint.
I need to use index as the chosen row number for a already defined SLOT() that gets a QModelIndex as argument when doubleClicked(QModelIndex) SIGNAL() is sent.
For now I use a workaround - In the QPushButton SLOT() I pass the QAbstractItem::doubleClicked(QModelIndex) SLOT() a non valid QModelIndex.
I check the validity - if valid I use index.row(), if not I call QListWidget::currentRow().Thanks for all the help
-
Then use the other signal from the QListWidget which gives you a QListWidgetItem. As I said - mixing them is cumbersome - either use the convenience model or an own but don't mix it.