Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it advisable to use a QStaticText to draw a small text label in a subclass of QGraphicsItem?

Is it advisable to use a QStaticText to draw a small text label in a subclass of QGraphicsItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 515 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    Greetings.

    I am implementing a subclass of QGraphicsItem, which draw a customized graphic item and also draw a small text label. The text is drawn based on the lower right corner of the bounding rect of my custom item.

    My question: Is it appropriate to use QStaticText in this case?, or is there a better option?

    Some considerations:

    • This is a small text label (although it could be of any length), in practice it is only a numeric value no more than five (5) digits.

    • Routinely, the text does not change very often.

    • So far, my class has a member variable of type QStaticText (contains the text is to be drawn).
      To draw the text using the QPainter::drawStaticText() function within MyGraphIt::paint( .. )

      This last consideration arises part of my question:

      The text in the QStaticText is put in constructor of my class (and modified infrequently, by appropriate function).

      In the function MyGraphIt::paint( .. ), the painter object is given as a parameter, with several settings already established (including the font), internally I only modify the color and width of the pen.

      I wonder if, in this context, I am taking advantage of the benefits of a QStaticText?, or conversely,
      I am imposing any unnecessary overhead?

    • The other part of my question arises from considering the alternatives:

      1. Use QPainter::drawText() to paint the text. This alternative creates a problem when calculating the bounding Rect of my item. I do not know how to calculate the bounding rect of a QString, since in the context in which this should be calculated (MyGraphIt::boundingRect()) I have no information on the font and would have to build a QPainter object (I think).

      2. Use QGraphicsSimpleTextItem. At first glance, it seems that this option requires more overhead during rendering.

    Thanks in advance for any help and/or suggestions regarding this matter.

    Isaac Pérez
    Programming is understanding.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved