PDA

View Full Version : 2 QListWidget - move Entry between Widgets



reinki0013
28th April 2010, 08:24
Hello,

I have a little problem with my application...

I have 2 QListWidgets which I make dynamic in a vertical layout (it also can be 3 QListWidgets) and I want to move an Entry from the 1 Widget in the 2 Widget and so on...

The move from one Widget to the other Widget is not the problem...
I want to check if the Entry was moved is already in this Widget.
I want to check if the Entry exists in the other Widget.

Is there any SIGNAL or Event where I can handle this?

I hope someone can help me...

greetings :)

Kumosan
28th April 2010, 09:16
Do you know the assistant? Gives you a fantastic overview, what signals/events a widget has and what not.
If you'd use it you'd quickly find that the answer is no.

And your question is a bit strange. You mean before the entry was moved? After the answer would always
be yes. And the test if an entry already exists:

QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
Finds items with the text that matches the string text using the given flags.

Also found in the assistant.

reinki0013
28th April 2010, 09:50
Thanks for your answer...

I mean after the entry was moved...
I need a Signal or something to connect to a function that I can check if an entry exists...

like
connect(listwidget, SIGNAL(currentItemChanged()....SLOT(WidgetChanged( )....

Kumosan
28th April 2010, 10:21
But after an entry was moved it always exists in the list widget. Isn't that the point of moving? ;)

There is no signal or event which tells you that a new item has been added.
Why do you need this signal? Don't you know when you add something in you
QListWidget? In that case you could emit such a signal yourself.
And you don't need a signal to check whether an entry exists. You call
QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
If the list is empty, the item does not exists.
Somehow I don't understand your requirements.

reinki0013
28th April 2010, 12:30
Now I`ve solved the problem...
I have seen in a book an example and I do it like this and now it works like I will...

When I move now something in the QListWidget I got in the function "dropEvent"...
That`s what I want...

But now I`ve a little problem...
I have to knew the sender. When I move, for instance from a red widget in a yellow widget, I have to knew from where the entry come...

Kumosan
28th April 2010, 13:05
Now I`ve solved the problem...
I have seen in a book an example and I do it like this and now it works like I will...

When I move now something in the QListWidget I got in the function "dropEvent"...
That`s what I want...

But now I`ve a little problem...
I have to knew the sender. When I move, for instance from a red widget in a yellow widget, I have to knew from where the entry come...

You did not mention drag and drop. ;)

But look here:
QWidget * QDropEvent::source () const