Qt World Summit: Submit your Presentation

UI Forms Custom Properties

  • Hi Everyone,

    I have a few forms for custom widgets etc, which for example have tree views on them. I have other widgets that can accept drag and drop events. I'm trying to uniquely identify these views such that the QGraphicsSceneDragDropEvent source for example can tell me where that event has originated from.
    There are a couple of methods I have thought about (trying to avoid having to subclass a treeview):

    • Use the object name - As the name space is lost this is not unique for the application.
    • Use QMetaInfo - for forms I’m not sure how to do this for auto generated forms.

    Anyone have any ideas?

    Thanks in advance.

  • Lifetime Qt Champion


    Out of curiosity, why do you need to know the widget from which the drag & drop operation started ?

  • For validation only certain items within the tree view are permissible to be dropped, and the behavior of the dragged from location has an impact on the drop behavior. As this is a plugin based application i'm trying to design something a bit more scalable .

    For example there is a tree view with elements that can be created, and a tree view of elements that already exist but can be shown. An element from the "create" tree view will create the object and then show it. Where as the one from the "show" tree view will only be shown. If that makes any sense.

  • Lifetime Qt Champion

    In that case shouldn't that information rather be encoded in the data you are passing around ? Doing so, you become independent on the widget from which the operation starts.

  • Perhaps. The problem was I was trying to make the item dropped agnostic to it's source. For example a QListWidget, a QTreeView etc. I felt at the time forcing the data type across all possible drag sources to comply with some interface was nothing something I wanted to do. I rather constrain the logic higher up to say "I am only interested in event from that / those source(s)". Leaving lower level logic to determine the type of object being passed and the action to take.

  • Lifetime Qt Champion

    You can then write a filter that you install and configure per widget.

  • @SGaist Apologies i'm late replying.

    Thanks for the useful thoughts. Do you mind if a through a couple more questions at you, whilst I try to knock up an example using your method.

    • Lets say i'm using a tree view and a list view to provide the drag from sources. I believe using your object I would have to cast the event source to one of these two types (tree or list) then obtain the selected item (i.e the item in the selection model) that was actually dragged onto the widget. Whilst this might be OK from a list view or tree view (only 2 branches), for more sources the amount of casts would potentially grow he same rate.

    • Again using the example of a list view providing a data item that is exposed through the native interface without having to do additional casting i think would be additional work. for example you might just want to use a standard item model.

    Hope that makes some sort of sense.

  • Lifetime Qt Champion

    One way to do the filtering more cleanly would be to use custom mime-types then in your drop target, you check that mime type and if not whitelisted then refuse the drop. No need for any knowledge of the widget where the item comes from.

Log in to reply