1

Topic: The rational job boundingRect for QMyGraphicsItem

Frequently at difficult  items to define boundingRect is, de facto, to double function paint. In this connection, apparently, it would be reasonable to define a limiting rectangle immediately in  paint, like virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override {m_BoundingRect = QRect (0,0,0,0); painter-> drawRect (0,0,10,20); m_BoundingRect = m_BoundingRect.united (QRect (0,0,10,20));//...} virtual QRectF boundingRect (void) const override {return m_BoundingRect;} But when I such tried to implement something, glitches all the same began. In this connection a question,  so it is possible to do, and if not so how nevertheless to solve a problem of the job of function boundingRect for difficult items?

2

Re: The rational job boundingRect for QMyGraphicsItem

3

Re: The rational job boundingRect for QMyGraphicsItem

4

Re: The rational job boundingRect for QMyGraphicsItem

5

Re: The rational job boundingRect for QMyGraphicsItem

Hello, Chorkov, you wrote: a C> Hello, _hum _, you wrote: a C>>> it is possible, my item were simply insufficiently difficult... But to take area "with a store" never was a problem. A C>>> Knowing the maximum possible size of an element, it is not clear what for it still to enumerate... So the maximum size also returned... __>> I am am strained, at first, by dubbing-in (if I edit  it is necessary to climb in boundingRect and to recall that there, yes as it is connected with  a figure), a C> How many there at you primitives (calls painter-> drow *** (...) ), on  everyone item? The C> If is a lot of (or if there are repeating pieces), probably, it is necessary to pass to composite item. Composite items not only that demand again operation by hands (routine  inheritance, designers, identifiers and so forth technical peel so also seriously brake copying if there is their adding/removal from a scene. Besides there appear then nuances with ability of a parent item to catch , to be dragged and so forth __>> and secondly, routine calculations (for example, calculation for oblique figures of type of arrows) a C> do not consider. The C> For arrows, for certain is fixed size. Simply increase a rectangle extensively by the double maximum size of an arrow + the maximum width of lines. And if the lines forming the image, it is a lot of? It is necessary to write maximum search __>> and logically it is as though correct that I will know a limiting rectangle only after I will draw a figure, instead of to. The C> In implementation so would be more convenient, but system , the size is necessary prior to the beginning . A C> This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item's bounding rect. QGraphicsView uses this to determine whether the item requires redrawing. The C> Is supposed what to estimate a rectangle it is possible much faster, than  an element. In the text resulted by you  it is told that it should be known to the first . It is told only that it is necessary for copying. That is, theoretically, QGraphicsView could store at itself the data about that, the first time or not  the given item and if the first, not to look on boundingRect. __>> an interesting variant, thanks. And what lacks of it. ? Though, , and a context of drawing another so, there can be problems... A C> If gathering to cause it on everyone boundingRect - yes there will be brakes. A C> Dependence from options - whether here it is necessary to look you use it in  generally... I do not use it, but after all in options not all information on specificity of a context of drawing is sewn up, as far as I understand (there like also QPaintDevice it is important), and QPicture can not coincide on these moments with QGraphicsView.