PDA

View Full Version : QTextEdit not receiving MouseButtonDblClick or MouseButtonPress



ComServant
9th April 2009, 22:00
Here's my event filter:


bool MainWindow::eventFilter(QObject *object, QEvent *event)
{

//QEvent::MouseButtonDblClick
if(event->type() == QEvent::MouseButtonPress)
{
if(object == ui->myQTextEdit)
{
assert(0);
}
else if(object == ui->myQLineEdit)
{
assert(0);
}
}

return QMainWindow::eventFilter(object, event);
}

Here's how I'm setting it up:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);

ui->myQTextEdit->installEventFilter(this);
ui->myQLineEdit->installEventFilter(this);
}

When I click on the QLineEdit, the assert triggers. Good. When I click on the QTextEdit, it does not trigger. :confused: The same happens with QEvent::MouseButtonDblClick. Double clicks work on the QLineEdit, and not on the QTextEdit.

I know the filter is set up right, because using something like QEvent::Enter triggers the assert on both QLineEdits and QTextEdits. (Also, I have more than one QTextEdit, and it doesn't work on either)

And here's the odd thing, the edging around the QTextEdits are receptive to presses and double clicks and trigger the asserts. The textual part of the QTextEdits are the parts that aren't receiving them, however.

Could someone confirm the ability to capture double and single clicks on QTextEdits in Qt 4.5? What did I do wrong?

Thank you in advance.

user_mail07
10th April 2009, 00:52
It looks there is something to do with viewport of textEditor.
You can try this. It worked for me.

QWidget * pWidget = myQTextEdit->viewport();
pWidget->installEventFilter(this);

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::MouseButtonPress)
{
if(obj == pWidget)
{
qDebug("TextEdit");
}
}

// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);

}

ComServant
10th April 2009, 02:06
Hey, that did it for me, thank you!

I was thinking there was some bug, or else that I'd have to create my own version of QTextEdit (which I wouldn't know how to do) to get it working.

Captures both presses and double clicks just fine, thanks.