[Qt-interest] Grabbing the mouse

Mihail Naydenov mlists at ymail.com
Mon May 16 09:16:49 CEST 2011


"(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