Results 1 to 2 of 2

Thread: Drag and Drop different item text in two QListWidgets

  1. #1
    Join Date
    Apr 2020
    Qt products
    Qt4 Qt5

    Default Drag and Drop different item text in two QListWidgets

    I have two QListWidgets , one named “Commands” on the left side and other named “XML Script” on the right side , I am able to drag and drop items from one List to another, How ever, when I drag one item, I don’t want drop that same item text, I want some changed text to be dropped.

    Example: In this example when I dragged “SetScroll Command” from “commands” QListWidget and I am trying to drop this in “XML Script” QListWidget , I need some different text to be dropped like If I drag ‘Pause Command’ from “Commands”, the dropped item in “XML Script ”should have item with text like “This is a Pause Command”

    ?? How can I achieve this, I am intending to keep a Map data structure which will have key as “Pause Command” and Value as “This is a Pause Command”. Whenever key text is dragged , value text shall be dropped,

    Any help appreciated.


  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 760 Times in 750 Posts
    Qt products
    Windows Android

    Default Re: Drag and Drop different item text in two QListWidgets

    I think from your previous post, you are already overriding mousePressEvent in your list widget to create a custom QDrag instance with the proper text mime type. Do the same thing here, except replace the list widget text with your XML string. If you will be dragging from the list widget into multiple other widgets, then you can add both "text/plain" and "text/xml" mime types to your QMimeData and select the one you want when you handle the drop event.

    In the XML list widget, you will need to write code to handle the dropEvent() and / or dragEnterEvent() to look for the "text/xml" type. If the mime data doesn't have it, you don't accept the drop. This will prevent drops of unrelated text dragged from somewhere else. You can handle these events by installing an event filter on the XML list widget.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Drag and Drop item outside from i-e filesystem
    By matsukan in forum Qt Quick
    Replies: 0
    Last Post: 26th August 2016, 14:12
  2. Replies: 2
    Last Post: 30th January 2014, 07:46
  3. Replies: 3
    Last Post: 10th June 2010, 16:13
  4. Drag and Drop between 2 QListWidgets
    By ShamusVW in forum Newbie
    Replies: 4
    Last Post: 28th April 2010, 14:42
  5. drag and drop with item views
    By castorvert in forum Qt Programming
    Replies: 14
    Last Post: 27th March 2006, 11:12

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.