This post has been merged into this thread!
Hello forum,
With the help of the forum i have made some changes to the diagram scene example where i added elliptical item as follows:
case Ellipse:
{
//declare an ellipse with the bounding rectange
myPolygon = item.shape().toFillPolygon();
}
break;
case Ellipse:
{
//declare an ellipse with the bounding rectange
QGraphicsEllipseItem item(-100,-50,200,100);
myPolygon = item.shape().toFillPolygon();
}
break;
To copy to clipboard, switch view to plain text mode
I wanted to use the very same idea to implement the intersection test in another project. In my project i have the graphical item has the following definitions for bounding rectange and shape functions:
QRectF RootGraphicsItem
::boundingRect() const {
//!get the bounding rectangle of the enclosing text
QRectF rect
= m_textGraphicsItem
->boundingRect
();
//the following condition decides if the boundary needs
//to be changed
if( rect.width() < m_drawRectMinimumWidth )
rect.setWidth(m_drawRectMinimumWidth);
if(rect.height() < m_drawRectMinimumHeight)
rect.setHeight(m_drawRectMinimumHeight);
//set the rectangle width with the text item spacing
rect.setWidth(rect.width() + getTextItemSpacing() );
//and return the rectangle
return rect;
}
//the following function is for better collission detection
{
QRectF ellipse_rect
= boundingRect
();
path.addEllipse(ellipse_rect);
return path;
}
QRectF RootGraphicsItem::boundingRect() const
{
//!get the bounding rectangle of the enclosing text
QRectF rect = m_textGraphicsItem->boundingRect();
//the following condition decides if the boundary needs
//to be changed
if( rect.width() < m_drawRectMinimumWidth )
rect.setWidth(m_drawRectMinimumWidth);
if(rect.height() < m_drawRectMinimumHeight)
rect.setHeight(m_drawRectMinimumHeight);
//set the rectangle width with the text item spacing
rect.setWidth(rect.width() + getTextItemSpacing() );
//and return the rectangle
return rect;
}
//the following function is for better collission detection
QPainterPath RootGraphicsItem::shape() const
{
QRectF ellipse_rect = boundingRect();
QPainterPath path;
path.addEllipse(ellipse_rect);
return path;
}
To copy to clipboard, switch view to plain text mode
But if i try to add the arrow item to my root graphics item using the line intersection example i get erratic behavior - the arrow is not attached to the item and disappears once you move the item inside the scene. You can also recreate the problem in the diagram scene example if you do the following changes
case Ellipse:
{
//declare an ellipse with the bounding rectange
// QGraphicsEllipseItem item(-100,-50,200,100);
myPolygon = item.shape().toFillPolygon();
}
break;
case Ellipse:
{
//declare an ellipse with the bounding rectange
// QGraphicsEllipseItem item(-100,-50,200,100);
QGraphicsEllipseItem item(0,0,200,100);
myPolygon = item.shape().toFillPolygon();
}
break;
To copy to clipboard, switch view to plain text mode
You also need to add the following line in the mainwindow.cpp and some additional changes in diagramitem.h:
layout->addWidget(createCellWidget(tr("Ellipse"),DiagramItem::Ellipse),2,0);
layout->addWidget(createCellWidget(tr("Ellipse"),DiagramItem::Ellipse),2,0);
To copy to clipboard, switch view to plain text mode
enum DiagramType
{
Step,
Conditional,
StartEnd,
Io ,
Ellipse
};
enum DiagramType
{
Step,
Conditional,
StartEnd,
Io ,
Ellipse
};
To copy to clipboard, switch view to plain text mode
I think i need to adjust some transformational issue here. But i have not found any good reference to it. The manual is not illustrative enough.
Any reference to this issue will be very helpful
Regards
Sajjad
Bookmarks