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. QGraphicsTextItem of unit dimension i.e. corresponding to unit rect i.e. a primitive so can be dragged out from one pixel size.
Forum Updated to NodeBB v4.3 + New Features

QGraphicsTextItem of unit dimension i.e. corresponding to unit rect i.e. a primitive so can be dragged out from one pixel size.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.9k 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.
  • B Offline
    B Offline
    bootchk
    wrote on last edited by
    #1

    I want a "primitive" QGraphicsTextItem of unit dimension that corresponds to a primitive QGraphicsRectItem having rect (0,0,1,1). (I call them glyphs. Usually a glyph means a primitive text character, a letter, that composes into words.) The user will drag out (rubberband) these shapes. Here, the primitive unit text item may have no contents or may have for example prototype text (to the user) such as "abc". Dragging them out simply scales them up from their unit size.

    I am having difficulty. I am setting font, and setting the pointSize of the font. It appears that I also need to set the margin of the underlying QTextDocument. One symptom is that the text appears much below and to the right of the cursor position (corresponding to the margin?) What are the units of QTextDocument.setDocumentMargin()? I am quessing that they are "characters".

    Another symptom is that the prototype text "abc" is rendered garbled, one character on top of another. I suppose I need to call QTextGraphicsItem.setTextWidth() with a reasonable value, say 12 (the user would want an initial text box to hold that many characters.) Note textWidth might better be called textWrappingWidth and is in units of characters also?

    I suppose that for a textWidth of say 3 characters, and points per pixel of say 1, I need to setPointSize of the unit textitem at approximately 1/3. More precisely I need to use font metrics since characters are usually less wide than tall.

    I would appreciate a reference to sample code. It should be a common idea.

    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