Results 1 to 6 of 6

Thread: Implementing drag and drop for existing widget

  1. #1
    Join Date
    Jul 2009
    Posts
    41
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Implementing drag and drop for existing widget

    I think I'm missing something fundamental. I have been trying to make existing widgets like QListView, QLineEdit accept drops from external applications. The documentation suggests that one needs to reimplement virtual methods such as DropEvent. I have certainly been able to do this by subclassing QLineEdit to MyLineEdit (for example) with no problem.

    However, there are properties such as "acceptDrops" defined for these widgets that would seem to suggest that it is possible to drop items into widgets without having to subclass them, simply adding code to the MainWindow class, for example. However, I have not been able to find any way to do this, I don't see any signals available to which I could connect and so forth.

    All the examples I have found do indeed subclass the widget. So what am I missing?

    Thanks,
    D

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing drag and drop for existing widget

    Have a look at the QWidget documentation, especially the part about the acceptDrops property. It should give you something to work with.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Jul 2009
    Posts
    41
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Implementing drag and drop for existing widget

    Appreciate the response. I saw all that before I posted .... it wasn't particularly informative. If you have a pointer to an actual example where a widget like QLineEdit dropped into a layout inside a MainWindow in QtCreator can be made to respond to drops without subclassing, I'd love to see it.

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing drag and drop for existing widget

    I don't have the possibility to test atm, but it is very likely that if you setAcceptDrops(true); then QLineEdit should accept them and display anything that is reasonably convertible to QString.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. #5
    Join Date
    Jul 2009
    Posts
    41
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Implementing drag and drop for existing widget

    That may be but how is the application notified that a drop has happened? I don't want to poll the widget.

  6. #6
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing drag and drop for existing widget

    Look for the textChanged(), textEdited() and editingFinished() signals that QLineEdit has.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Replies: 0
    Last Post: 2nd June 2010, 17:52
  2. Drag and drop inside and outside a Widget
    By utopia500 in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2010, 16:20
  3. Drag and drop inside and outside a Widget
    By utopia500 in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 13:42
  4. Drag and Drop a widget in and out QTabWidget
    By smarinr in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2008, 19:10
  5. Replies: 1
    Last Post: 18th November 2008, 06:57

Bookmarks

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.