[Qt-interest] Mouse click on QTextBrowser.

Christopher Probst cprobst at ics.com
Fri Mar 19 11:24:27 CET 2010


Hello  Niedgodziwy,

I would make the following changes to make it work. Since QTextBrowser  
inherits from QAbstractScrollArea, the mouse events you are trying to  
catch "belong" to QAbstractScrollArea::viewport(). In the context of  
your example,
this means that two occurrences of brw should be replaced by brw- 
 >viewport().

Instead of

> brw->installEventFilter(this);

in constructor Dialog::Dialog(QWidget *parent, Qt::WindowFlags flags),  
do

  centralWidget->viewport()->installEventFilter(this);


And instead of

> if(target == brw &&
> 	   (event->type() == QEvent::MouseButtonPress ||
> 		event->type() == QEvent::MouseButtonDblClick ||
> 		event->type() == QEvent::MouseButtonRelease))



in Dialog::eventFilter(QObject* target, QEvent* event) do

if(target == brw->viewport() &&
              (event->type() == QEvent::MouseButtonPress ||
                   event->type() == QEvent::MouseButtonDblClick ||
                   event->type() == QEvent::Mo...


I tried on my Mac and the dialog does close on a Mouse-press.

I hope this helps,
Christo





  



More information about the Qt-interest-old mailing list