[Qt-interest] Grabbing the mouse

Mihail Naydenov mlists at ymail.com
Tue May 17 08:48:16 CEST 2011


----- Original Message ----

> From: phil prentice <philp.cheer at talktalk.net>
> To: qt-interest at qt.nokia.com
> Sent: Mon, May 16, 2011 10:31:46 AM
> Subject: Re: [Qt-interest] Grabbing the mouse
> 
> Hi MihaiNaydenov
>   Thanks for your reply.  The reason why I am  grabbing the mouse is because I 

> want to have the ability of selecting  coordinates outside of the view.  This 
> would become more of an issue  when for example I might wish to create a 
> circle that has a centre outside  of the view, but I wish to capture that 
> centre point in order to create the  circle.  In the case of a line I might be 

> zoomed in, and again wish to  draw a line whose end point lies outside of the 
> view.  Ideally I would  also prefer the ability to use points outside of the 
> scene, but this might  not be possible.
> Regardless of all of that, surely grabmouse should eneable  that widget to 
> capture the coordinates of the mouse regardless to where they  are placed?
> Is'nt that what grab mouse is supposed to do???
> 

Looking how other programs solve this - the view scrolls when user is near the 
edge and is still drawing.

Clicking outside the app window and expecting an input is weird and I doubt It 
has good support on the platforms.
Mouse grab is intended for widgets to steal mouse events from other widgets, 
dont know how relevant this concept is across application windows.

As a help tool you can install an event filter on the window or on the entire 
app to see exactly what events are delivered in that scenario and see what is 
going on.

MihailNaydenov

> Thanks  again
> 
> Phil
> 
> On Monday 16 May 2011 07:16, Mihail Naydenov  wrote:
> > "(which can be outside of the window)"
> >
> > Outside  the app window, this is? This surly can be the problem.
> >
> >
> >  MihaiNaydenov
> >
> >
> > ----- Original Message  ----
> >
> > > From: phil prentice <philp.cheer at talktalk.net>
> >  > To: qt-interest at qt.nokia.com
> > >  Sent: Mon, May 16, 2011 9:28:18 AM
> > > Subject: [Qt-interest] Grabbing  the mouse
> > >
> > > Hi
> > >   I've got a widget  derived from QGraphicsView
> > > The first time a  user presses the  mouse I grab the mouse and store the
> > > first set of   coordinates(of a line).
> > > I then move the cursor around and select  the second  coordinate of the
> > > line (which can be outsoide of  the window).  This in  turn was going to
> > > release  the
> > >
> > > mouse.  Unfortunately the application   completely locks the user out. 
> > > The mouse no longer works for  any  widget including the one that grabbed
> > > it. Please see code  below. Its probably  obviuos but what am I doing
> > >  wrong??
> > >
> > > Thanks for your  help
> > >  Phil
> > >
> > >
> > > // VIRTUAL
> > > void   myQGraphicsView::mousePressEvent(QMouseEvent *event)
> > > {
> >  >    qDebug("Mouse press event = %d,%d",event->x(),  event->y() );
> > >    qDebug("Mouse press event =  %d,%d",event->globalX(), event->globalY() 
> > > ); QPointF pt =  mapToScene(event->x(), event->y());
> > >     qDebug("Mouse scenepress event = %E,%E", pt.x(), pt.y());
> > >
> >  >    if(m_GraphicsItem)
> > >   {
> > >      qDebug("Before  release");
> > >      releaseMouse();
> > >     qDebug("After   release");
> > >     QGraphicsLineItem *line =   static_cast<QGraphicsLineItem
> > > *>(m_GraphicsItem);
> >  >      QPen pen(QColor(mainwindow_ui::penColour));
> >  >      line->setPen(pen);
> > >      line->setLine(m_pt1x, m_pt1y,   pt.x(), pt.y());
> > >      scene()->addItem(m_GraphicsItem);
> > >       m_GraphicsItem = NULL;
> > >   }
> > >   else
> >  >   {
> > >       grabMouse(Qt::CrossCursor);
> > >     m_GraphicsItem =  new  QGraphicsLineItem;
> > >     m_pt1x =   pt.x();
> > >      m_pt1y =  pt.y();
> >  >   }
> > >    event->accept();
> > >  }
> > > _______________________________________________
> > >  Qt-interest  mailing list
> > > Qt-interest at qt.nokia.com
> > >  http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> _______________________________________________
> 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