You are not logged in.

Dear visitor, welcome to KDE-Forum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

boyadg

Beginner

  • "boyadg" started this thread

Posts: 11

Location: Barcelona

  • Send private message

1

Wednesday, May 19th 2004, 12:16pm

klistview drag and drop

Hi, it's me again.

Today's problem has to do with a KListView I have in my app. I would like it to support dnd, but I can't get it to work.

First I did:

MyList->setAcceptDrops( TRUE );
connect( MyList, SIGNAL( dropped( QDropEvent*, QListViewItem* ) ), this, SLOT( slotDropped( QDropEvent*, QListViewItem* ) ) );

Then I made the slotDropped function

MyApp::slotDropped( QDropEvent* event, QListViewItem* after)
{
kdDebug << "slotDropped called" << endl;
}

Only to find out it never gets called! Not surprisingly, if I drag something over my KListView, it shows a cross as if it doesn't accept the drop.

After investigating, I found a lot of messages saying that acceptDrag(QDropEvent*) has to be overridden.

Does that mean I have to subclass KListView?

and if so:
How do I get Qt Designer to use the subclass instead of the normal KListView?

And what does the acceptDrag function have to do? Does it have to check if what is dropped is valid and return true if that's so?


These are probably stupid questions, but I've been searching for the answers all morning and I can't seem to find them. Almost all examples use subclassed KListViews, but I don't see how I can do that while using Qt Designer.

Thanks

ceebx

Beginner

Posts: 1

Location: Germany

  • Send private message

2

Wednesday, May 19th 2004, 11:28pm

RE: klistview drag and drop

Yes, you will need to subclass KListView and tell it if you are able handle the drag object by overwriting acceptDrag(). QDragObject subclasses usually offer a canDecode(QDropEvent*) method, so an implementation for acceptDrag could be:

Source code

1
2
3
4
bool MyListViewacceptDrag(QDropEvent *event) const
{
    return QTextDrag::canDecode( event );
}


You can integrate the widget in Qt designer with Tools|Custom|Edit Custom Widgets.

This post has been edited 1 times, last edit by "ceebx" (May 19th 2004, 11:29pm)


boyadg

Beginner

  • "boyadg" started this thread

Posts: 11

Location: Barcelona

  • Send private message

3

Thursday, May 20th 2004, 8:26am

Thanks, I'm gonna try right now!