Home > Mobile >  How do custom graphics item use QGraphicsItem: : shape () function
How do custom graphics item use QGraphicsItem: : shape () function

Time:09-16

The problems in the recent development of:
Inheritance QGraphicsItem, custom graphics, rewrite the paint and boundingRect, because the graphic is irregular, so want to be able to return to the primitive shape, probably not just rectangular box, refer to the help documents rewrite shape (), returns the area or boundingRect rectangular box, check a lot of information online, and to help document, hope which friend glad

CodePudding user response:

Rewrite the shape ()
Calculate your irregular area then returns a path

CodePudding user response:

Thanks for returning my post,
I'd rewrite the, similar to the following simple rewrite the shape () function:
QPainterPath path;
Path. AddEllipse (boundingRect ());
Return path.

Then I was in the paint () function inside painting out of the area:
Painter - & gt; DrawPath (shape ());
Display or rectangle boundary, not ellipse,
Also write the other code, after return to irregular region, but in the end with paint or rectangular area of the display,

Don't use it, or I where do wrong, but the inside of the QT documentation example is also I write the code above, so now just don't know what to do,
Looking for information online, is said to rewrite the shape () returns the primitive shape accurately, used to receive events, collision detection and so on,,,,

CodePudding user response:

 
QPainterPath shape () const;

I think you are lost the const, lead to the failure function to rewrite

CodePudding user response:

Const QPainterPath ConnectLine: : shape ()
{
QPainterPathStroker stoker.
Stoker. SetWidth (6);
Return stoker. CreateStroke (path);
}

CodePudding user response:

I found that the problem is: the scene of the mouse click event default call graph yuan boundingRect () function, and don't call me rewrite the shape () function,
You have encountered such a situation?

CodePudding user response:

Post your code, unless you write the function name is wrong, or certainly can do it,

CodePudding user response:

CodePudding user response:

You put the path with the qdebug output, if the object is invalid, do call boundingrect back

CodePudding user response:

Invalid, breaking point it is no use, will only to boundingRect (),

CodePudding user response:

references 9 f qq_35335034 response:
invalid, breaking point it is no use, will only to boundingRect (), and

You use qdebug output, don't interrupt point
Then you drag the item, let the scene trigger shape call
What output information

CodePudding user response:

brief reference to the tenth floor nanjing spring reply:
Quote: references 9 f qq_35335034 response:

Invalid, breaking point it is no use, will only to boundingRect (), and

You use qdebug output, don't interrupt point
Then you drag the item, let the scene trigger shape call
Look at what the output information

How is he didn't call shape function, call the bounding

CodePudding user response:

Need to make sure your boundingRect () returns whether it is Valid, that is wide and high as an integer, there is a Valid QRect function,

CodePudding user response:

Oh, lose the wrong, is positive
  •  Tags:  
  • Qt
  • Related