PDA

View Full Version : Detect widget doubleclick



Grzyboo
28th July 2015, 14:21
I have tried 2 things:
1. mouseDoubleClickEvent
It worked fine for unclickable widgets like QLabels but did not work for clickable ones like PlainTextEdit or PushButton.

2. eventFilter
Seems to work fine for QLabel as well.
It works for PlainTextEdit but not as intended. It detects a double click only if i click at the very edge of widget (what is like 1 pixel). If I double click the main widget area(where you can put text in) nothing really happens.



class myEventFilter: public QObject
{
public:
myEventFilter(QObject *parent):QObject(parent) {};

bool eventFilter(QObject* object,QEvent* event)
{
if(event->type() == QEvent::MouseButtonDblClick)
{
qDebug() << "Widget double clicked";
return true;
}
else
return QObject::eventFilter(object,event);
}
};




ui->plainTextEdit->installEventFilter(new myEventFilter(this));

anda_skoa
28th July 2015, 15:00
For the plain text edit, install the even filter in the edit's viewport widget.

Cheers,
_

Grzyboo
28th July 2015, 15:15
Oh, great, thanks for the advice.