How to catch rightclick event on QComboBox item? I tried reimplement mousePressEvent for my custom combobox, but not luck The event just for ComboBox it self, not for Item.
How to catch rightclick event on QComboBox item? I tried reimplement mousePressEvent for my custom combobox, but not luck The event just for ComboBox it self, not for Item.
http://doc.qt.digia.com/qt/qcombobox...etItemDelegate implement own QAbstractItemDelegate and implement own events. Afte that set item delegate. And wala it will work
Can I use mousePressEvent in abstractitemdelegate?
Btw, I want make different emit signal for left and right click on combobox item.
Yes of course and now example for mouseevent:
You can use mouseReleaseEvent or MousePressEventQt Code:
{ if(event->button() == Qt::RightButton) { emit rightClick(); } if(event->button() == Qt::LeftButton) { emit leftClick(); } };To copy to clipboard, switch view to plain text mode
Last edited by Viper666; 13th January 2013 at 11:55.
Not work
Qt Code:
{ if (e->button()==Qt::LeftButton) { qDebug() << "Klik Kiri"; } if (e->button()==Qt::RightButton) { qDebug() << "Klik Kanan"; } }To copy to clipboard, switch view to plain text mode
Btw, how can I know index of item selected?
Oh sorry my mistake i mean QItemDelegate
At first you must have working delegate like in this example http://programmingexamples.net/wiki/...mboBoxDelegate and when you own delegate works you can implement mouseEvent if it will not work post here you code.
Of course I use QItemDelegate. But not work
Qt Code:
#ifndef COMBOBOXDELEGATE_H #define COMBOBOXDELEGATE_H #include <QItemDelegate> { Q_OBJECT public: protected: signals: public slots: }; #endif // COMBOBOXDELEGATE_HTo copy to clipboard, switch view to plain text mode
Qt Code:
#include "comboboxdelegate.h" #include <QMouseEvent> #include <QDebug> { } { if (e->button()==Qt::LeftButton) { qDebug() << "Klik Kiri"; } if (e->button()==Qt::RightButton) { qDebug() << "Klik Kanan"; } }To copy to clipboard, switch view to plain text mode
I only need catch mouse event. And get what item index is selected...
I will write a example for you. But now i can' sorry. I don't know why it doesn't work but i think it has some solution
Oh, no problem.
Btw, thanks for your response
ok i solved it.
Solution: in QItemDelegate isn't mousePressEvent or something like that this are events from Qobject but this don't work for QItemDelegate you need implement editorEvent:
Qt Code:
bool Item::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { { if(mouseEvent->button() == Qt::LeftButton) qDebug() << "leftButton"; if(mouseEvent->button() == Qt::RightButton) qDebug() << "rightButton"; } }To copy to clipboard, switch view to plain text mode
Last edited by Viper666; 13th January 2013 at 21:30.
wirasto (13th January 2013)
Bookmarks