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. SOLVED: Why isn't my QGraphicsTextItem movable? (draggable with mouse)
QtWS25 Last Chance

SOLVED: Why isn't my QGraphicsTextItem movable? (draggable with mouse)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k Views
  • 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.
  • P Offline
    P Offline
    Phil Weinstein
    wrote on last edited by
    #1

    My QGraphicsTextItems (subclass) do show a selection ornamentation. But the user can't move them by dragging with the mouse. What am I missing? (This is with Qt 4.8.5 on Windows 7, 64 bit). Below are the relevant QGraphicsTextItem calls made within my subclass constructor. (I've also tried doing these things after the item is inserted into the scene).

    @OcanTextGfxItem::OcanTextGfxItem (TextData* textData,
    OutputCanvasScene* gfxScene)
    : QGraphicsTextItem (NULL),
    _textData (textData), // TextData*, not ownership
    _scene (gfxScene) // OutputCanvasScene*
    {
    setFlags (QGraphicsItem::ItemIsMovable |
    QGraphicsItem::ItemIsFocusable |
    QGraphicsItem::ItemIsSelectable);

    setPlainText (tr ("Test Text"));
    setEnabled (true);
    setVisible (true);
    }@

    Thank you in advance.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Phil Weinstein
      wrote on last edited by
      #2

      SOLVED -- "Z Value". The problem was that a large mostly-transparent QGraphicsPixmapItem (image) -- used as a background image -- was getting in the way of my QGraphicsTextItems. I had forgotten to set the "Z" value of those text items [with QGraphicsItem::setZValue (qreal z)]. This prevented the mouse from being able to drag (move) the text item.

      See the accompanying image ... notice the text item in the bottom left ... and the mostly transparent image (chutes and ladders) ... http://cadswes2.colorado.edu/~philw/pub/TextItem-Zvalue.png

      !http://cadswes2.colorado.edu/~philw/pub/TextItem-Zvalue.png(QGraphicsView image)!

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Tricky one ! What surprises me is that the text doesn't really look like it's been covered e.g. the 1996.

        Anyway, glad you found out and thanks for sharing !

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Phil Weinstein
          wrote on last edited by
          #4

          SGaist, thanks for sharing that observation. What you refer to ("text doesn't actually look like it's been covered") WAS the cause for my original oversight -- i.e. the text didn't look covered, so I didn't initially understand that it was underneath the background image QGraphicsPixmapItem.

          But in the screenshot above, the text item NOW DOES have a "Z" value higher than the background image item's "Z" value. That was required for the text item to be picked up with the mouse (for dragging with the mouse).

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            That was well understood, however I thought that you posted a screenshot of when you had the problem :)

            A before/after would be interesting to see

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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