Important: Please read the Qt Code of Conduct -

Change the appearance of a dragged QStandardItem

  • Hello!

    In the development of my application, I'd like to drag'n'drop QStandardItems from a TreeView into another QWidget. I'm able to do this easily enabling dragging of the TreeView and the item to drag, though I'd like the dragged item to change it's appearance, so that the textual representation in the tree view changes into a more elaborated widget of my creation.

    Is it thus possible to transform the appearance of the "ghost" of the dragged item into something different, loaded for example from a .ui file?

    I'm posting here in the General and Desktop because I think it's not bound to, but I'm using PySide6, if it might matter.

    Thank you :)

  • Lifetime Qt Champion


    You will need to reimplement the startDrag method of your item view.

    I would recommend to take a look the implementation to grab some ideas.

  • Could I create the "QWidget of my dreams (tm)" and, in the startDrag method initialize an instance of that qwidget and call its startDrag method?

  • Lifetime Qt Champion

    What QWidget do you want to use in your dragEvent ?

  • I need to create a custom QWidget which graphically appears something like the elements in this image:


    I'm actually trying to kind of replicate that flow chart interface. I was thinking of creating the widget in a .ui file, or directly creating it entirely programmatically (is it possible?) using a factory / builder to setup the inputs, the outputs, the name and the header's color.

    The idea thus is to be able to drag not a text, but the ghost of the element which will be then dropped in the working area (see the following screenshot of my WIP).


  • Lifetime Qt Champion

    You will want to check the Graphics View framework.

    And yes, that kind of interface will be easier to code. The "core" part with the item view and the central widget can be done with designer but you will have to use widget promotion for your custom tree view.

  • Returning to the (main) topic,

    do you have any idea if you can overwrite the startDrag protected method from the PySide library? I kind of doubt it.

    Otherwise it'd be fine to just drag a generic placeholder PNG (QPixmap?)

    Thanks :)

  • Lifetime Qt Champion

    Sure you can, the usual way, subclass and reimplement.

Log in to reply