[Qt-interest] setMouseTracking
"Alexander Carôt"
alexander_carot at gmx.net
Thu Jan 6 23:31:49 CET 2011
Hej Jan,
that is a cool idea and it was indeed possible to set the setMouseTracking for my new QDesktopWidget class (in which I overwrote the mouse handlers respectively), however, they didn't fire even with a pressed mousebutton. I did it this way:
//// MAIN ///
#include <QApplication>
#include "desktopWidget.h"
int main(int argc, char *argv[]){
QApplication yo(argc,argv);
desktopWidget *dW = new desktopWidget();
dW = (desktopWidget*) yo.desktop();
return yo.exec();
}
/// DESKTOP WIDGET ///
#include <iostream>
#include <QMouseEvent>
#include <QEvent>
#include <QDesktopWidget>
using namespace std;
class desktopWidget : public QDesktopWidget{
public:
desktopWidget();
bool event(QEvent *e);
void mouseMoveEvent ( QMouseEvent * event );
void mousePressEvent( QMouseEvent *event );
};
If you have any further idea please let me know.
Thanks, best
Alex
-------- Original-Nachricht --------
> Datum: Thu, 06 Jan 2011 18:45:38 +0100
> Von: Jan <janusius at gmx.net>
> An: qt-interest at qt.nokia.com
> Betreff: Re: [Qt-interest] setMouseTracking
> Just an idea:
>
> Maybe it is possible to install an eventfilter on the QDesktopWidget
>
> QDesktopWidget * QApplication::desktop ()
>
> Through an eventfilter you may get mouse events. No idea if you can
> enable mousetracking for the desktop widget (but it is a widget subclass
> - so why not).
>
> Jan
>
> Am 06.01.2011 16:39, schrieb "Alexander Carôt":
> >> Does your main window derive from QMainWindow or just QWidget? If not,
> >> what happens if you create a QMainWindow and set your current "main
> >> window" widget as the QMainWindow's centralWidget()? I believe this
> >> should work (and is the common way of implementing a top level
> >> application window.)
> >
> > In fact my window derives from QWidget. Changing it to QMainWindow makes
> it receive mouseMoveEvents without clicking as desired - thank you !
> >
> > However, it does not work if the mouse resides outside the window. So I
> changed my class back to QWidget and followed your suggestion of creating
> an extra QMainWindow and set my widget as the central widget via
> setCentralWidget(); In that context I also overwrote the mouse event handler of the
> QMainWindow with mouse pos messages. Unfortunately this didn't solve the
> problem either: Only the central widget's handler fired only when placing the
> mouse on it and not outside the widget's boundaries.
> >
> > Did I correctly follow you suggestion or am I possibly mistaken ?
> >
> > Thanks and best
> >
> > Alex
> >
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
--
http://www.carot.de
http://www.triologue.de
Email : Alexander at Carot.de
Tel.: +49 (0)177 5719797
Ihr GMX Postfach immer dabei: die kostenlose GMX Mail App für Android.
Komfortabel, sicher und schnell: www.gmx.de/android
More information about the Qt-interest-old
mailing list