[Qt-interest] Fwd: Re: setMouseTracking
Jan
janusius at gmx.net
Thu Jan 6 23:57:39 CET 2011
Hm, I suppose you cant create your own desktopwidget. That is why I
suggested to use an eventfilter. But this idea is kind of wired. Have
not tried it .-) :
In you mainwindow overwrite virtual eventFilter(....) function and in
the constructor install it on the desktop like
QApplication::desktopWidget()->installEventFilter(this);
Jan
Am 06.01.2011 23:31, schrieb "Alexander Carôt":
> 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
>
More information about the Qt-interest-old
mailing list