Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 184491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:18:06+00:00 2026-05-11T15:18:06+00:00

Drawing on a QPicture should update its bounding rect. Like this: >>> picture =

  • 0

Drawing on a QPicture should update its bounding rect. Like this:

>>> picture = QPicture() >>> painter = QPainter(picture) >>> picture.boundingRect() QRect(0,0,0,0) >>> painter.drawRect(20,20,50,50) >>> picture.boundingRect() QRect(20,20,50,50) 

But if I draw text on it, the bounding rect isn’t updated:

>>> picture = QPicture() >>> painter = QPainter(picture) >>> picture.boundingRect() QRect(0,0,0,0) >>> painter.drawText(10,10, 'Hello, World!') >>> picture.boundingRect() QRect(0,0,0,0) 

Obviously, it doesn’t update the bounding rect.

Is there a way to make it repsect drawn text or do I have to do it manually? (Not too hard, but I hope that Qt can assist me here.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:18:07+00:00Added an answer on May 11, 2026 at 3:18 pm

    Take a look at these overload methods, where you must specify the Bounding Rectangle after the text parameter (which is apparently different than the rectangle in the first argument’s position):

    Draws the given text within the provided rectangle according to the specified flags. The boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text.

    QPainter.drawText (1), QPainter.drawText (2)

    Update:

    It appears if you want to generate a bounding rectangle for the drawText() method in advance, you just call the boundingRect() method on QPainter, which does the following:

    Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle with the specified flags using the currently set font(); i.e the function tells you where the drawText() function will draw when given the same arguments.

    If the text does not fit within the given rectangle using the specified flags, the function returns the required rectangle.

    QPainter.boundingRect

    I linked to BoundingRect with QRectF output, but the information applies to the other versions as well.

    So basically, pass the result of QPainter.boundingRect() into the boundingRect parameter of the QPainter.drawText() method (the second QRect argument).

    Update 2:

    I APOLOGIZE PROFUSELY for being so damn dense. I forgot that drawText works differently in PyQt than in Qt. The bounding rectangle is RETURNED by the drawText function (not passed in like Qt) and in addition, you have to specify alignment flags before you get a bounding rectangle given back to you. (I even included the p.end() as per Aaron Digulla’s comment):

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

    Here is the output:

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

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

    So it appears you will have to set the bounding rectangle yourself, though at least it is returned to you by the output of the drawText() method when passing in flags.

    This does not seem like ideal behaviour, that you would have to set the bounding rectangle yourself. I hope someone else has the answer you’re looking for, but I suspect you may want to report this bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

- (void)drawRect:(CGRect)rect { // Drawing code. stickerImage = [UIImage imageNamed:@betaImage.png]; CGSize size = stickerImage.size;
I'm drawing points on a map with OpenLayers like in this example: http://dev.openlayers.org/examples/draw-feature.html Now
I am drawing a line on a control on my Windows form like this:
Drawing a blank on this, and google was not helpful. Want to make a
This drawing shows a tree of parent-child relationships. It is directed, without cycles. A
While drawing graphics in 2D, how can I handle the depth of a picture
I'm drawing a bunch of UIImageView (100x100) as menu items. Each has its own
On drawing on canvas if i use this code to draw the bitmap then
I am currently drawing a Bitmap to a SurfaceView using Canvas.drawBitmap() . This seems
I'm drawing inspiration from this question: Convert Linq to Sql Expression to Expression Tree

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.