PDA

View Full Version : Counting the QListWidget Items by a QLineEdit each Drag&Drop event.



comvis
11th May 2019, 18:19
Hello Qt devs, I'm pretty new to qt and I would like to ask for a simple problem:
_ I have a MainWindow with:
+ An initial widget for storing initial items.
+ 10 list widgets for storing dropped items.
+ A line edit inside a for showing a "count" variable which count how many items in there.
What I want to do is after dropping a item in these 10 widgets, the "count" number plus one, and dragging an item outside the list widgets the "count" minus one. I tried eventFilter but after installingEventFilter to a widget, the dropped item dissappears. I have stuck at this for many hours so hopefully someone could give me a solution.

anda_skoa
12th May 2019, 10:46
You don't need any event filter for that.

Each list widget has a model for its data and each model has signals for when it adds or removes items.

Simply connect to these and update the count.

Cheers,
_

comvis
12th May 2019, 12:19
Can you tell me what is this Signal, is this viewportEntered or Entered. Thanks for your reply.

anda_skoa
12th May 2019, 15:10
QAbstractItemModel::rowsInserted() and QAbstractItemModel::rowsRemoved().

Cheers,
_