Click event for QListWidgetItem
-
@shreya_agrawal said in Click event for QListWidgetItem:
However, the control never goes into the second if block.
I would say your filtered object never receives the events, because they are handled in the
QListWidgetItem
directly and not propagated any further. -
@shreya_agrawal said in Click event for QListWidgetItem:
QPoint pos = mouseEvent->pos(); QListWidgetItem *item = listWidget->itemAt(pos);
First check if you get into
if(event->type() == QEvent::MouseButtonPress)
when you do press the button on an item. If so, verify (I'm not going to do it) that the coordinates you receive and pass in these two statements have the same "origin"/what they are relative to (e.g. is mouse pos global and item pos relative to list widget?), I am not sure they do else in principle it should work. -
@shreya_agrawal said in Click event for QListWidgetItem:
However, the control never goes into the second if block.
No, I don't get in this loop when I click on a QListWidgetItem.
I thought you had 2
if
s, I didn't see 3 :( ! -
@shreya_agrawal said in Click event for QListWidgetItem:
Then, is there any other workaround apart from using the signal slot mechanism?
Yes. You need to work with
QListQWidget::viewport
. You can't do it directly on application event filter. See solutions discussed at https://stackoverflow.com/a/42475218/489865 (also https://www.qtcentre.org/threads/20961-why-QListWidget-can-t-get-QEvent-MouseButtonPress) and consider if you can integrate them into your approach (which I have no idea why you are doing, but that's up to you). -
BTW: Installing an event filter on
QApplication
directly might not be the greatest idea. As your app grows the filter- and event delivery mechanism might become very buggy and laggy as a result of your code that is executed on basically anything that happens within your app. -
Just like QListQWidget's events are processed in its viewport, is there something similar for a QCalendarWidget?
I used this event filter to capture the click event on my calendar widget:
bool Class::eventFilter(QObject *obj, QEvent *event) { if(obj == ui->dateEdit->calendarWidget()) { if(event->type() == QEvent::MouseButtonPress) { qDebug() << "Calendar Widget Clicked"; } } return QObject::eventFilter(obj, event); }
But the control never goes in the second if block.
-
It worked by installing the event filter on the table view of the calendar widget:
ui->dateEdit->calendarWidget()->findChild<QTableView*>("qt_calendar_calendarview")->viewport()
-