qt - Is there a way to make drawText() update a QPicture's bounding rect? -


Drawing on

a QPicture , its bounding text should be updated like this:

  & gt; & Gt; & Gt; Image = QPicture ()> & Gt; & Gt; Painter = QPainter (picture) & gt; & Gt; & Gt; Picture.boundingRect () QRect (0,0,0,0) & gt; & Gt; & Gt; Painter.drawRect (20,20,50,50) & gt; & Gt; & Gt; But if I remove the text on it, the bounding record is not updated:  
   

Code> & gt; & Gt; & Gt; Image = QPicture ()> & Gt; & Gt; Painter = QPainter (picture) & gt; & Gt; & Gt; Picture.boundingRect () QRect (0,0,0,0) & gt; & Gt; & Gt; Painter.drawText (10,10, "Hello, World!") & Gt; & Gt; & Gt; picture. Bowling Rescue () QRect (0,0,0,0)

Obviously, it does not update the bounding act.

Is there a way to erase this drawn text or do I have to do it manually? (Not very difficult, but I hope QT can help me here.)

In Have a look at overload methods, where you must specify the bounding rectangle after the text parameter (which is different from the rectangle in the case of first logic):

The text given in accordance with the given text Underlines the designated flag

,

Update:

/ Strong>

this copy It seems that if you want to generate a border rectangle for the drawText () method, then you call the boundingRect () method on the couponer, which does the following:

Returns the border of the text rectangle, as if using the current rectangle (current) font, it will appear when dragged inside the given rectangle with the given flag; That is, the function tells you where the draw text will be drawn when given the same argument.

If the text is not fit within a given rectangle using specific rectangles, then the function returns the required rectangle.

I am connected to BoundingRect with QRectF output, but this information also applies to other versions.

So basically, pass QPainter's results into the boundingRect parameter of Q.Painter.drawText () method (second QRXTR argument) in .boundingRect ().

Update 2:

I apologize completely enough to be so dense that I forgot that drawText works differently in Qt than in PyQt . The border rectangle is returned by the drawText function (such as not passed in QT) and besides, you must specify alignment flags before receiving a boundary rectangle given to you. (I was also involved in Pend (according to Aaron Degula's comment):

  pic = Qt.QPicture () p = QtGui.QPainter (pic) brect = p.drawText (10, 10,200,200, QtCore.Qt.AlignCenter, "blah") p.end () Print Print Print. Pic.boundingRect ()  

Here is the output:

PyQt4.QtCore.QRect (100, 103, 20, 14)

PyQt4.QtCore.QRect (0, 0, 0, 0)

It looks like you have to set your border rectangle, though at least it draws you during the draw The text () method is returned by the output.

It does not look like ideal behavior, you have to set yourself a boundary rectangle. I hope someone else has your answer, but I suspect you can report this bug Are there.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -