Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, October 2006
qmouseEvent handling


Message 1 in thread

hello everyone, i am trying to make a widget that will receive
mousePressEvent(QMouseEvent *e) for a widget of mine.
the thing is i have a QTextEdit that occupies most of the screen and
thus mouseEvents do not propagate to the widget which is my receiver
of choice for these events...
i read about QMouseEvent::ignore() but i am not sure this is what i
want... i basically want to make the textEdit (and any other objects
like buttons ill add later) 'transparent' so mouseEvents are directly
interpreted by the QWidget class.. ie the main window.
thank you
nass

--
 [ signature omitted ] 

Message 2 in thread

hello everyone, i am trying to make a widget that will receive
mousePressEvent(QMouseEvent *e) for a widget of mine.
the thing is i have a QTextEdit that occupies most of the screen and
thus mouseEvents do not propagate to the widget which is my receiver
of choice for these events...
i read about QMouseEvent::ignore() but i am not sure this is what i
want... i basically want to make the textEdit (and any other objects
like buttons ill add later) 'transparent' so mouseEvents are directly
interpreted by the QWidget class.. ie the main window.
thank you
nass

--
 [ signature omitted ] 

Message 3 in thread

Hi,

)\(@sS escribió:
> hello everyone, i am trying to make a widget that will receive
> mousePressEvent(QMouseEvent *e) for a widget of mine.
> the thing is i have a QTextEdit that occupies most of the screen and
> thus mouseEvents do not propagate to the widget which is my receiver
> of choice for these events...
> i read about QMouseEvent::ignore() but i am not sure this is what i
> want... i basically want to make the textEdit (and any other objects
> like buttons ill add later) 'transparent' so mouseEvents are directly
> interpreted by the QWidget class.. ie the main window.
> thank you
> nass
Maybe an eventfilter on your main window can help you. Check for mouse 
move events there.

Regards,
Javier.

--
 [ signature omitted ] 

Message 4 in thread

On 10/9/06, )(@sS <athanasios.silis@xxxxxxxxx> wrote:
> hm i started making some sense.. but it doesn't work properly.
> here is my .ui.h code:
>
> void alarmScreen::init()
> {
>     textScreen->installEventFilter( this );
> }
>
> void alarmScreen::closeButton_clicked()
> {
>     //delete the alarm codes
>     accept();
> }
>
>
> void alarmScreen::upButton_clicked()
> {
>     textScreen->scrollBy(0,-60);
> }
>
>
> void alarmScreen::downButton_clicked()
> {
>     textScreen->scrollBy(0,60);
> }
>
>
> void alarmScreen::mousePressEvent( QMouseEvent *e )
> {
>     printf("%d,%d\n",e->x(),e->y());
> }
>
>
> bool alarmScreen::eventFilter( QObject *obj, QEvent *ev )
> {
>     //printf("got in\n");
>     QMouseEvent *e=(QMouseEvent *)ev;
>     if ( obj == textScreen )
>     {
>         printf("its the textEdit\n");
>         if ( e->type() == QEvent::MouseButtonPress )
>         {
>             printf("ad%d,%d\n",e->x(),e->y());
>             return TRUE;
>         }
>     }
>     else
>     {
>         printf("af: %d,%d\n",e->x(),e->y());
>         // pass the event on to the parent class
>         //return QMainWindow::eventFilter( obj, ev );
>     }
> }
>
> basically my form (alarmScreen) is a QWidget (640x320) and on top of
> it sits a QFrame of the same dimensions. Then on the frame sit: a
> QTextEdit (in read only mode) and 3 buttons (a closeBt, a scrollUp and
> a scrollDown). it basically a trivial log viewer but i did not use the
> standard scrollbars of the QTextEdit because i need bigger buttons.
> anyhow then i thought since it is so trivial i can delete the 2 scroll
> buttons and use the whole widget area for doing the scrolling (half
> the widget for scroll up and the other half for scroll down - forget
> the close button for a while).
>
> what i did manage with the above code .. is that when i 'cross' the
> border of the QTextEdit  alarmScreen::eventFilter is run and the
> printf() statement is executed... but of course
>         if ( e->type() == QEvent::MouseButtonPress) fails since i have not
> clicked any button.
> what i had initially done was to implement the
> void alarmScreen::mousePressEvent( QMouseEvent *e ) function
> but that only works when i click on the frame... not when i click
> somewhere insie the QTextEdit...
>
> any ideas or pointers?
> thank you for your help
> nass
>
> On 10/9/06, Javier Díaz <jdiaz@xxxxxxxxxxx> wrote:
> > Hi,
> >
> > )\(@sS escribió:
> > > hello everyone, i am trying to make a widget that will receive
> > > mousePressEvent(QMouseEvent *e) for a widget of mine.
> > > the thing is i have a QTextEdit that occupies most of the screen and
> > > thus mouseEvents do not propagate to the widget which is my receiver
> > > of choice for these events...
> > > i read about QMouseEvent::ignore() but i am not sure this is what i
> > > want... i basically want to make the textEdit (and any other objects
> > > like buttons ill add later) 'transparent' so mouseEvents are directly
> > > interpreted by the QWidget class.. ie the main window.
> > > thank you
> > > nass
> > Maybe an eventfilter on your main window can help you. Check for mouse
> > move events there.
> >
> > Regards,
> > Javier.
> >
> >
>

--
 [ signature omitted ] 

Message 5 in thread

Hi,

)\(@sS escribió:
> hm i started making some sense.. but it doesn't work properly.
> here is my .ui.h code:
>
> void alarmScreen::init()
> {
>    textScreen->installEventFilter( this );
> }
>
> void alarmScreen::closeButton_clicked()
> {
>    //delete the alarm codes
>    accept();
> }
>
>
> void alarmScreen::upButton_clicked()
> {
>    textScreen->scrollBy(0,-60);
> }
>
>
> void alarmScreen::downButton_clicked()
> {
>    textScreen->scrollBy(0,60);
> }
>
>
> void alarmScreen::mousePressEvent( QMouseEvent *e )
> {
>    printf("%d,%d\n",e->x(),e->y());
> }
>
>
> bool alarmScreen::eventFilter( QObject *obj, QEvent *ev )
> {
>    //printf("got in\n");
>    QMouseEvent *e=(QMouseEvent *)ev;
>    if ( obj == textScreen )
>    {
>     printf("its the textEdit\n");
>     if ( e->type() == QEvent::MouseButtonPress )
>     {
>         printf("ad%d,%d\n",e->x(),e->y());
>         return TRUE;
>     }
>    }
>    else
>    {
>     printf("af: %d,%d\n",e->x(),e->y());   
>     // pass the event on to the parent class
>     //return QMainWindow::eventFilter( obj, ev );
>    }
> }
If you take a look at 
http://doc.trolltech.com/4.2/qobject.html#eventFilter you'll see you 
need to pass the events you don't take care of, so uncomment your last 
return line.

>
> basically my form (alarmScreen) is a QWidget (640x320) and on top of
> it sits a QFrame of the same dimensions. Then on the frame sit: a
> QTextEdit (in read only mode) and 3 buttons (a closeBt, a scrollUp and
> a scrollDown). it basically a trivial log viewer but i did not use the
> standard scrollbars of the QTextEdit because i need bigger buttons.
> anyhow then i thought since it is so trivial i can delete the 2 scroll
> buttons and use the whole widget area for doing the scrolling (half
> the widget for scroll up and the other half for scroll down - forget
> the close button for a while).
>
> what i did manage with the above code .. is that when i 'cross' the
> border of the QTextEdit  alarmScreen::eventFilter is run and the
> printf() statement is executed... but of course
>     if ( e->type() == QEvent::MouseButtonPress) fails since i have not
> clicked any button.
That's right ;)

> what i had initially done was to implement the
> void alarmScreen::mousePressEvent( QMouseEvent *e ) function
> but that only works when i click on the frame... not when i click
> somewhere insie the QTextEdit...
>
> any ideas or pointers?
> thank you for your help
> nass
>
Well, if you expect to get mouse events, you're doing right AFAIK. In 
your eventfilter you can get events for every object contained on 
alarmScreen, so isn't what you want?
About alarmScreen::mousePressEvent(), this function is called before you 
ignore the event on eventfilter, but only will take mouse press events 
to your alarmScreen widget. Your frame is transparent if you receive 
events clicking on it.
Also, look at http://doc.trolltech.com/4.2/eventsandfilters.html , to 
understand the event system.

Regards,
Javier

--
 [ signature omitted ] 

Message 6 in thread

Thank you for the links i went through them.
in reality the behaviour is very weird, clicking right on the frame
border of the textEdit works properly just it does if i click on the
alarmScreen frame. but no luck on the main area of the textEdit... it
is as if for some reason its dead.. as if mouse click events are
intercepted by something else before the ::eventFilter
implementation... which is impossible of course but still..
here is what it looks like now:

bool alarmScreen::eventFilter( QObject *obj, QEvent *ev )
{
    //printf("got in\n");
    QMouseEvent *e=(QMouseEvent *)ev;
    if ( obj == textScreen )
    {
	printf("its the textEdit\n");
	if ( e->type() == QEvent::MouseButtonRelease )
	{
	    printf("ad%d,%d\n",e->x(),e->y());
	    return TRUE;
	}
	else
	{
	    return FALSE;
	}
    }
    else
        if ( obj == this ) // the main QWidget
	    if ( e->type() == QEvent::MouseButtonRelease )
	    {
	    printf("af%d,%d\n",e->x(),e->y());
	    return TRUE;
	}
	else
	{
	    return FALSE;
	}	
    else
    {
	printf("sending event to parent");
	return alarmScreen::eventFilter( obj, ev );
    }
}

i somehow feel that i need to write a similar procedure.. of the sort
textScreen::eventFilter() that intercepts mouseButtonPress (or
Release) events and it decides whether to process them or to sent them
to the parent window (the alarmScreen)... but of course it cant happen
as a simple procedure since there is no such thing as
textScreen::eventFilter() inside the class alarmScreen...
any ideas?
thank you for your help
nass




On 10/10/06, Javier Díaz <jdiaz@xxxxxxxxxxx> wrote:
> Hi,
>
> )\(@sS escribió:
> > hm i started making some sense.. but it doesn't work properly.
> > here is my .ui.h code:
> >
> > void alarmScreen::init()
> > {
> >    textScreen->installEventFilter( this );
> > }
> >
> > void alarmScreen::closeButton_clicked()
> > {
> >    //delete the alarm codes
> >    accept();
> > }
> >
> >
> > void alarmScreen::upButton_clicked()
> > {
> >    textScreen->scrollBy(0,-60);
> > }
> >
> >
> > void alarmScreen::downButton_clicked()
> > {
> >    textScreen->scrollBy(0,60);
> > }
> >
> >
> > void alarmScreen::mousePressEvent( QMouseEvent *e )
> > {
> >    printf("%d,%d\n",e->x(),e->y());
> > }
> >
> >
> > bool alarmScreen::eventFilter( QObject *obj, QEvent *ev )
> > {
> >    //printf("got in\n");
> >    QMouseEvent *e=(QMouseEvent *)ev;
> >    if ( obj == textScreen )
> >    {
> >     printf("its the textEdit\n");
> >     if ( e->type() == QEvent::MouseButtonPress )
> >     {
> >         printf("ad%d,%d\n",e->x(),e->y());
> >         return TRUE;
> >     }
> >    }
> >    else
> >    {
> >     printf("af: %d,%d\n",e->x(),e->y());
> >     // pass the event on to the parent class
> >     //return QMainWindow::eventFilter( obj, ev );
> >    }
> > }
> If you take a look at
> http://doc.trolltech.com/4.2/qobject.html#eventFilter you'll see you
> need to pass the events you don't take care of, so uncomment your last
> return line.
>
> >
> > basically my form (alarmScreen) is a QWidget (640x320) and on top of
> > it sits a QFrame of the same dimensions. Then on the frame sit: a
> > QTextEdit (in read only mode) and 3 buttons (a closeBt, a scrollUp and
> > a scrollDown). it basically a trivial log viewer but i did not use the
> > standard scrollbars of the QTextEdit because i need bigger buttons.
> > anyhow then i thought since it is so trivial i can delete the 2 scroll
> > buttons and use the whole widget area for doing the scrolling (half
> > the widget for scroll up and the other half for scroll down - forget
> > the close button for a while).
> >
> > what i did manage with the above code .. is that when i 'cross' the
> > border of the QTextEdit  alarmScreen::eventFilter is run and the
> > printf() statement is executed... but of course
> >     if ( e->type() == QEvent::MouseButtonPress) fails since i have not
> > clicked any button.
> That's right ;)
>
> > what i had initially done was to implement the
> > void alarmScreen::mousePressEvent( QMouseEvent *e ) function
> > but that only works when i click on the frame... not when i click
> > somewhere insie the QTextEdit...
> >
> > any ideas or pointers?
> > thank you for your help
> > nass
> >
> Well, if you expect to get mouse events, you're doing right AFAIK. In
> your eventfilter you can get events for every object contained on
> alarmScreen, so isn't what you want?
> About alarmScreen::mousePressEvent(), this function is called before you
> ignore the event on eventfilter, but only will take mouse press events
> to your alarmScreen widget. Your frame is transparent if you receive
> events clicking on it.
> Also, look at http://doc.trolltech.com/4.2/eventsandfilters.html , to
> understand the event system.
>
> Regards,
> Javier
>
>

--
 [ signature omitted ] 

Message 7 in thread

mmh, textedit uses it's own eventfilter, but you tell it to use yours, 
so don't understand why can't you get the events.

Try catching this "ev->type() == QEvent::ContextMenu". Probably textedit 
is using this event.

Hope this helps you,
Javier.

)\(@sS escribió:
> Thank you for the links i went through them.
> in reality the behaviour is very weird, clicking right on the frame
> border of the textEdit works properly just it does if i click on the
> alarmScreen frame. but no luck on the main area of the textEdit... it
> is as if for some reason its dead.. as if mouse click events are
> intercepted by something else before the ::eventFilter
> implementation... which is impossible of course but still..
> here is what it looks like now:
>
> bool alarmScreen::eventFilter( QObject *obj, QEvent *ev )
> {
>    //printf("got in\n");
>    QMouseEvent *e=(QMouseEvent *)ev;
>    if ( obj == textScreen )
>    {
>     printf("its the textEdit\n");
>     if ( e->type() == QEvent::MouseButtonRelease )
>     {
>         printf("ad%d,%d\n",e->x(),e->y());
>         return TRUE;
>     }
>     else
>     {
>         return FALSE;
>     }
>    }
>    else
>        if ( obj == this ) // the main QWidget
>         if ( e->type() == QEvent::MouseButtonRelease )
>         {
>         printf("af%d,%d\n",e->x(),e->y());
>         return TRUE;
>     }
>     else
>     {
>         return FALSE;
>     }   
>    else
>    {
>     printf("sending event to parent");
>     return alarmScreen::eventFilter( obj, ev );
>    }
> }
>
> i somehow feel that i need to write a similar procedure.. of the sort
> textScreen::eventFilter() that intercepts mouseButtonPress (or
> Release) events and it decides whether to process them or to sent them
> to the parent window (the alarmScreen)... but of course it cant happen
> as a simple procedure since there is no such thing as
> textScreen::eventFilter() inside the class alarmScreen...
> any ideas?
> thank you for your help
> nass
>
>
>
>
> On 10/10/06, Javier Díaz <jdiaz@xxxxxxxxxxx> wrote:
>> Hi,
>>
>> )\(@sS escribió:
>> > hm i started making some sense.. but it doesn't work properly.
>> > here is my .ui.h code:
>> >
>> > void alarmScreen::init()
>> > {
>> >    textScreen->installEventFilter( this );
>> > }
>> >
>> > void alarmScreen::closeButton_clicked()
>> > {
>> >    //delete the alarm codes
>> >    accept();
>> > }
>> >
>> >
>> > void alarmScreen::upButton_clicked()
>> > {
>> >    textScreen->scrollBy(0,-60);
>> > }
>> >
>> >
>> > void alarmScreen::downButton_clicked()
>> > {
>> >    textScreen->scrollBy(0,60);
>> > }
>> >
>> >
>> > void alarmScreen::mousePressEvent( QMouseEvent *e )
>> > {
>> >    printf("%d,%d\n",e->x(),e->y());
>> > }
>> >
>> >
>> > bool alarmScreen::eventFilter( QObject *obj, QEvent *ev )
>> > {
>> >    //printf("got in\n");
>> >    QMouseEvent *e=(QMouseEvent *)ev;
>> >    if ( obj == textScreen )
>> >    {
>> >     printf("its the textEdit\n");
>> >     if ( e->type() == QEvent::MouseButtonPress )
>> >     {
>> >         printf("ad%d,%d\n",e->x(),e->y());
>> >         return TRUE;
>> >     }
>> >    }
>> >    else
>> >    {
>> >     printf("af: %d,%d\n",e->x(),e->y());
>> >     // pass the event on to the parent class
>> >     //return QMainWindow::eventFilter( obj, ev );
>> >    }
>> > }
>> If you take a look at
>> http://doc.trolltech.com/4.2/qobject.html#eventFilter you'll see you
>> need to pass the events you don't take care of, so uncomment your last
>> return line.
>>
>> >
>> > basically my form (alarmScreen) is a QWidget (640x320) and on top of
>> > it sits a QFrame of the same dimensions. Then on the frame sit: a
>> > QTextEdit (in read only mode) and 3 buttons (a closeBt, a scrollUp and
>> > a scrollDown). it basically a trivial log viewer but i did not use the
>> > standard scrollbars of the QTextEdit because i need bigger buttons.
>> > anyhow then i thought since it is so trivial i can delete the 2 scroll
>> > buttons and use the whole widget area for doing the scrolling (half
>> > the widget for scroll up and the other half for scroll down - forget
>> > the close button for a while).
>> >
>> > what i did manage with the above code .. is that when i 'cross' the
>> > border of the QTextEdit  alarmScreen::eventFilter is run and the
>> > printf() statement is executed... but of course
>> >     if ( e->type() == QEvent::MouseButtonPress) fails since i have not
>> > clicked any button.
>> That's right ;)
>>
>> > what i had initially done was to implement the
>> > void alarmScreen::mousePressEvent( QMouseEvent *e ) function
>> > but that only works when i click on the frame... not when i click
>> > somewhere insie the QTextEdit...
>> >
>> > any ideas or pointers?
>> > thank you for your help
>> > nass
>> >
>> Well, if you expect to get mouse events, you're doing right AFAIK. In
>> your eventfilter you can get events for every object contained on
>> alarmScreen, so isn't what you want?
>> About alarmScreen::mousePressEvent(), this function is called before you
>> ignore the event on eventfilter, but only will take mouse press events
>> to your alarmScreen widget. Your frame is transparent if you receive
>> events clicking on it.
>> Also, look at http://doc.trolltech.com/4.2/eventsandfilters.html , to
>> understand the event system.
>>
>> Regards,
>> Javier
>>
>>
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ]