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. Change the appearance of a dragged QStandardItem
Forum Updated to NodeBB v4.3 + New Features

Change the appearance of a dragged QStandardItem

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 569 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.
  • J Offline
    J Offline
    jim87
    wrote on last edited by
    #1

    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?

    P.S.
    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 :)

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

      Hi,

      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.

      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
      1
      • J Offline
        J Offline
        jim87
        wrote on last edited by
        #3

        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?

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

          What QWidget do you want to use in your dragEvent ?

          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
          • J Offline
            J Offline
            jim87
            wrote on last edited by jim87
            #5

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

            9e9c8597-f2ea-4e82-b53a-7c90ab7cd4fb-immagine.png

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

            02f81020-2b9f-43db-af82-361adb8ee790-immagine.png

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

              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.

              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
              • J Offline
                J Offline
                jim87
                wrote on last edited by
                #7

                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 :)

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

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

                  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