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



  • 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.



  • 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)!


  • Lifetime Qt Champion

    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 !



  • 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).


  • Lifetime Qt Champion

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.