ListWidget "How to check Mouse Event" when item has been clicked?
-
Hi folks,
After an listwodget item has been clicked I want to check the mouse button, and react on the left/right button differently.
I have this code in my app. But since I added "QMouseEvent *e" to the function nothing happens any longer ...void MyApp::on_listWidget_itemClicked(QMouseEvent *e) { if (e->button() == Qt::LeftButton){ int no = ui->listWidget->currentRow(); QString cn = ui->listWidget->currentItem()->text(); if( ui->listWidget->currentItem()->isSelected() ) { sendMessage("Item deactivated: " + cn + " Index :" + QString::number(no), msg_debug); } else { sendMessage("Item activated: " + cn + " Index :" + QString::number(no), msg_debug); } } }
Regards Alex
-
@ademmler said in ListWidget "How to check Mouse Event" when item has been clicked?:
QMouseEvent
For that you have to override https://doc.qt.io/qt-5/qwidget.html#mousePressEvent
See here how to do that: https://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html -
Hi
Just so its clear.You cannot go around and add/change parameters to Widgets build in signals.
ItemClicked() signal is
on_listWidget_itemClicked(QListWidgetItem *item)and if you change the parameter (item) then your slot will no longer be called.