Click event for QListWidgetItem
-
@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()
-