Home > Mobile >  Qt5.9.4 the same location, the view can obtain primitives, sence cannot obtain the primitives
Qt5.9.4 the same location, the view can obtain primitives, sence cannot obtain the primitives

Time:09-18

Sence of setSceneRect function called set size of (0,0,600,400); Draw a straight line (0, 0) to (200200), in order to accurately select line, overloading the shape function, call the qDebug output primitives, QGraphicsView call item () function can always return to the primitive, but using QGraphicsSence call ItemAt () function returns null pointer really (some of the same location, the view can obtain figure yuan, sence cannot obtain the figure yuan),

Const QRectF CLineItem: : boundingRect ()
{
Return shape (). ControlPointRect ();
}

Const QPainterPath CLineItem: : shape ()
{

QPainterPath path;
If (m_line==QLineF ())
Return path.

Path. The moveTo (0, 0);
Path. The lineTo (200200);

QPainterPathStroker stoker.
Stoker. SetWidth (2);
Stoker. SetJoinStyle (Qt: : MiterJoin);
Stoker. SetCapStyle (Qt: : RoundCap);
Stoker. SetDashPattern (Qt: : DashLine);
Return stoker. CreateStroke (path);

}

Void XXXGraphicsView: : mousePressEvent (QMouseEvent * event)
{

If (event - & gt; Button ()==Qt: : LeftButton)
{
QPoint point=event - & gt; Pos ();
for(int i=0; i<601; + + I)
{
for(int j=0; J<401; + + j)
{
QGraphicsItem * item1=itemAt (QPoint (I, j));
If (item1)
{
QDebug () & lt; <" The view "& lt; }

QPointF pt=mapToScene (QPoint (I, j));
Item2 QGraphicsItem *=m_pScene - & gt; ItemAt (pt, the transform ());
If (item2)
{
QDebug () & lt; <" Sence "& lt; }
}
}
}
QGraphicsView: : mousePressEvent (event);
}
  •  Tags:  
  • Qt
  • Related