[Qt-interest] Grabbing the mouse
phil prentice
philp.cheer at talktalk.net
Mon May 16 08:28:18 CEST 2011
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();
}
More information about the Qt-interest-old
mailing list