[Qt-interest] Grabbing the mouse

phil prentice philp.cheer at talktalk.net
Mon May 16 09:31:46 CEST 2011


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???

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



More information about the Qt-interest-old mailing list