It would help if you provided a minimal compilable example reproducing the problem.
It would help if you provided a minimal compilable example reproducing the problem.
Hi
I have managed to recreate the same problem i am having in my project by doing the following changes in the diagramscene example:
Inside the diagramitem.h file i added another item as follows:
Qt Code:
enum DiagramType { Step, Conditional, StartEnd, Io , Ellipse };To copy to clipboard, switch view to plain text mode
Inside the diagramitem constructor i have added the following:
Qt Code:
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 am sure not how to do this arrow and elliptical intersection test where in my project i have defined the bounding rectangle and shape for the elliptical item as follows:
Qt Code:
{ //!get the bounding rectangle of the enclosing text //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 path; path.addEllipse(ellipse_rect); return path; }To copy to clipboard, switch view to plain text mode
There are some affine transformation issues need to be taken care of - i guess and i am not sure how to do it. Do i have call some translation command before calling the ellipse drawing function ? I tried this as well and it became messier.
Looking forward to some useful hint over this .
Thanks
Sajjad
Hi
i have inserted the function call prepareGeometryChange inside the following function at arrow.cpp of the updated diagram scene example to recreate the problem.
Qt Code:
void Arrow::updatePosition() { prepareGeometryChange(); //declare a new line setLine(line); }To copy to clipboard, switch view to plain text mode
And the above function is called as follows:
Qt Code:
{ //if the dialgram items change is about the item positional change //then we need to notify the component items about the changes { //all the arrows connected to //it need to update its position foreach (Arrow *arrow, arrows) { arrow->updatePosition(); } } return value; }To copy to clipboard, switch view to plain text mode
But i am having the same problem - The arrow does not attach to the intersection point. I am attaching all the sources now. I hope that it will be more
illustrative to solve the issue. If i change the code in diagramitem.cpp as follows the problem is solved here as i mentioned in my previous post.
Qt Code:
myPolygon = item.shape().toFillPolygon();To copy to clipboard, switch view to plain text mode
But in my original project, the graphical items bounding rectangles starting point is from (0,0,width,height). And i do want to implement this intersection test there as well. Please make some time to go through this and help me solve the problem.
Regards
Sajjad
I meant prepareGeometryChange() for your RootGraphicsItem class. Its bounding rect depends on the size of the text (and possibly some other things) yet you never inform graphics view the size of the item might have changed.
In the last post i missed to include the source that i did some changes. Sorry.
arrow.cppdiagramitem.cppdiagramitem.harrow.h
Please go through it and suggest me to get it fixed.
Regards
Sajjad
Added after 9 minutes:
Yes it is true that the size of the bounding rectangle is based on the size of the text and predefined text spacing. And i am defining the size of the item inside the boundingRect() function, do i need to call the prepareGeometryChange() inside the boundingRect() and even if i do i get the following error:
Qt Code:
RootGraphicsItem.cpp:671: error: passing ‘const RootGraphicsItem’ as ‘this’ argument of ‘void QGraphicsItem::prepareGeometryChange()’ discards qualifiersTo copy to clipboard, switch view to plain text mode
Regards
Sajjad
Last edited by sajis997; 8th February 2012 at 11:25.
I call the prepareGeometryhange() inside the definition of boundary rectangle but it gives me the error as follows:
Qt Code:
RootGraphicsItem.cpp:668: error: passing ‘const RootGraphicsItem’ as ‘this’ argument of ‘void QGraphicsItem::prepareGeometryChange()’ discards qualifiersTo copy to clipboard, switch view to plain text mode
I guess that it is not the right place to call the prepareGeometryChange(), as i am doing it now:
Qt Code:
{ prepareGeometryChange(); //!get the bounding rectangle of the enclosing text //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; }To copy to clipboard, switch view to plain text mode
According to the manual it should be called once the set bounding rectangle is about to change. I am deciding the size before setting the bounding rectangle.
Any more suggestion ?
Calling that method from within boundingRect() wouldn't make sense. You need to call it when the actual change occurs (like when the text or spacing is changed).
Hi
This is what i think as well. I am changing the text later after defining the bounding rectangle.
Could you please figure out any another reason that the arrow item and elliptical item intersection test is not functioning ?
Regards
Sajjad
Hi
I am sorry. I did not get your last post. Did i cause something to distract from the main issue here. Let me summarize again:
I am trying to make connections between arrow and elliptical items in my own project and i tried to use the concept of diagramscene example.
I am having trouble to implement it - as the arrow is not properly attached to the elliptical items and they suddenly disappear once i start to move the elliptical items in the scene view.
I recreated the problem in the diagram scene example and posted in the forum for your point of view. All the details are mentioned in the previous posts.
Now please guide me where should i start from to debug this problem ?
Regards
Sajjad
Correct the bounding rect issue as it may have influence on how your scene is rendered in the view. Once that is done and it's not something that causes the misbehaviour, we can look elsewhere. Otherwise you can prepare a minimal compilable example reproducing the problem and we can work on that.
Hi
I would like to know what do i have to do to correct the bounding rect issue of the elliptical graphics item. Its bounding rectangle is based on the bounding rectangle of the text graphics item it contains. Text graphics item that is contained inside the elliptical item is in turn the subclass of QTextGraphicsItem. I would like to repeat that once that the bounding rect is defined inside the boundingRect() it is never changed since then and this is why i do not see any reason to call the prepareGeometryChange() function.
Could you please mention what might be wrong in the bounding rect function
Qt Code:
{ prepareGeometryChange(); //!get the bounding rectangle of the enclosing text //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; }To copy to clipboard, switch view to plain text mode
Otherwise i am attaching the files again which is compilable that recreates the problem in another project. All that you need to do is that create another copy of the diagramscene example, remove the diagramscene.h and diagramscene.cpp and add the following files:
diagramsceneview.h
diagramsceneview.cpp
diagramitem.h
diagramitem.cpp
And you have add the following line inside the createToolBox() of mainwindow.cpp
Qt Code:
layout->addWidget(createCellWidget(tr("Ellipse"),DiagramItem::Ellipse),2,0);To copy to clipboard, switch view to plain text mode
If you mange some time and compile with these added files and the reamaining files as arrived with the example you will see the problem
The arrow is not connected as it is supposed to .
Let me know if you have any trouble to compile them .
Regards
Sajjad
Bookmarks