qtablewidget drag and drop move row

2,900 views
Skip to first unread message

Luigi Ferraris

unread,
Mar 30, 2013, 1:38:27 PM3/30/13
to qtcon...@googlegroups.com
Hi to everyone.
I need to move row[s] between two QTablewidget objects; I'm able to enable drag&drop but always a copy action is performed.

I think this settings QTableWidget:setDefaultDropAction ( Qt::MoveAction ) as documented in http://qt-project.org/doc/qt-4.8/qtablewidget-members.html can solve my problem but it seems not working.

Can everyone give me help.

Cheers

Luigi Ferraris

Luigi Ferraris

unread,
Apr 6, 2013, 12:02:41 PM4/6/13
to qtcon...@googlegroups.com
Hi guys,
I have not read any reply to this message (help request): I am the only one who has this need?
I have writed about QTableWidget but this operation can be done also with other object: QTreeWidget, QListWidget, etc.
I think can be very interesting in a gui application....

Anyway....

Cheers

Pritpal Bedi

unread,
Apr 6, 2013, 6:30:44 PM4/6/13
to qtcon...@googlegroups.com
Hi Luigi


I have not read any reply to this message (help request): I am the only one who has this need?
I have writed about QTableWidget but this operation can be done also with other object: QTreeWidget, QListWidget, etc.
I think can be very interesting in a gui application....


Not everybody can reply to your message, it was extremely complex.
Only those who have had the need to do so and have already done can do so.
So until above creteria is met by one, you need to investigate yourself.


Pritpal Bedi
 

Luigi Ferraris

unread,
Apr 7, 2013, 11:17:21 AM4/7/13
to qtcon...@googlegroups.com
Il 07/04/2013 0.30, Pritpal Bedi ha scritto:
Not everybody can reply to your message, it was extremely complex.
Only those who have had the need to do so and have already done can do so.
So until above creteria is met by one, you need to investigate yourself.

Hi Pritpal, many thanks for your answer but probably my english is very bad.... As I write in previous message I'm able to do "drag&drop" between (ie) two QTablewidget.
But with current HbQt methods it is only possible to do a copy not a move (move add a "remove" action from source object).

In a very brief code example: oObject-1 and oObject-2 are two QTablewidget. I want to do a "drag&drop" action but only from oObject-2 to oObject-1.
I can set:
oObject-1 := QTablewidget(....)
oObject-1:setDragEnabled(.T.)
oObject-1:setDropIndicatorShown(.T.)
oObject-1:setDragDropMode( QAbstractItemView_DropOnly )
oObject-1:viewport:setAcceptDrops(.T.)

oObject-2 := QTablewidget(....)
oObject-2:setDragEnabled(.T.)
oObject-2:setDropIndicatorShown(.T.)
oObject-2:setDragDropMode( QAbstractItemView_DragOnly )
oObject-2:viewport:setAcceptDrops(.F.)

This code works fine but you can only perform a copy (see below) of items from oObject-2 to oObject-1
I think that :setDefaultDropAction( Qt_MoveAction ) can solve the problem as documented in
http://qt-project.org/doc/qt-4.8/qabstractitemview.html#defaultDropAction-prop

defaultDropAction
: Qt::DropAction

This property holds the drop action that will be used by default in QAbstractItemView::drag().

If the property is not set, the drop action is CopyAction when the supported actions support CopyAction.

This property was introduced in Qt 4.6.

Access functions:

Qt::DropAction defaultDropAction () const
void setDefaultDropAction ( Qt::DropAction dropAction )

So, can be enabled :defaultDropAction and :setDefaultDropAction methods?
I don't know if you must write (ie) a C++ workaround to have these abilities with HbQt or it's only required to add these "void" for setting up different behaviour.
If I was able to write C++ I was very happy to help you: I'm sorry.

Luigi Ferraris

Luigi Ferraris

unread,
Apr 8, 2013, 12:07:02 PM4/8/13
to qtcon...@googlegroups.com
Il 08/04/2013 9.07, Pritpal Bedi ha scritto:
2013-04-08 00:04 UTC-0800 Pritpal Bedi (bedipritpal at hotmail.com)(r201)
  * hbqt/qtgui/qth/QAbstractItemView.qth
    + Added: DragDropMode dragDropMode () const
             void setDragDropMode ( DragDropMode behavior )
       For Qt 4.6 and above. Pointed out by Luigi.
 
Hi Pritpal,
after your improvement, I want share my experience using drag and drop with qtablewidget

My problem was: I want MOVE item[s] from one object (source) to the other one (target).

You can see the starting situation in 00.jpg: on the left side target object on the right side source object
starting

Then I select (only) one row from source (see 01.jpg)
select

Then I do a drag and drop MOVEaction; you can see the end in 02.jpg
end


To perform this operation, I have used for:
- SOURCE object (right side)
   :setDragEnabled( .T. )
   :setDropIndicatorShown(.T.)
   :setDefaultDropAction( Qt_MoveAction )
   :setDragDropMode( QAbstractItemView_DragOnly )
     :setDragDropOverwriteMode( .F. )

- TARGET object (left side)
   :viewport:setAcceptDrops(.T.)
   :setDragEnabled( .T. )
   :setDropIndicatorShown(.T.)
   :setDragDropMode( QAbstractItemView_DropOnly )
     :setDragDropOverwriteMode( .T. )
    
I hope this can be useful for hbqt users.

A problem (I must investigate better):
I have coded :connect( QEvent_Drop, { |e| udf_drop(e) } ) for both objects, but I can't trace anything into udf_drop function

Many thanks
Best regards
Luigi Ferraris

Pritpal Bedi

unread,
Apr 8, 2013, 2:32:13 PM4/8/13
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi


I hope this can be useful for hbqt users.

Certainly.
It is better to write a small demo app for this to be understood by a beginner.


Pritpal Bedi
 

Luigi Ferraris

unread,
Apr 9, 2013, 5:05:00 AM4/9/13
to Pritpal Bedi, qtcon...@googlegroups.com
Il 08/04/2013 20.32, Pritpal Bedi ha scritto:
Certainly.
It is better to write a small demo app for this to be understood by a beginner.


Pritpal Bedi
Hi Pritpal.
In attachement you can find a sample. I hope is clear and usable.
Fell free to do changes to follow HbQt / Harbour rules (ie coding style).

I want to show two different usage: COPY action and MOVE action.
Different settings can give different behaviour: it's to long to show any combinations....
I have include some links to give idea where find other infos on QT docs.

I confirm problem related with QEvent_Drop usage: it seems not fired on.
I've not used in sample, but you can test it adding
:connect( QEvent_Drop, { | e | QDrop(e) } )

to every QTableWidget and add this function at the end of source

STATIC FUNCTION QDrop( e )
    LOCAL oQtObject := e:source()
    MsgBox( oQtObject:className() )
RETURN .F.

Cheers

--
Luigi Ferraris
mail: luigfe...@gmail.com
website: www.L3W.it

This e-mail is confidential and may also contain privileged information.
If you are not the intended recipient you are not authorised to read, print, save, process or disclose this message.
If you have received this message by mistake, please inform the sender immediately and delete this e-mail, its attachments and any copies.
Any use, distribution, reproduction or disclosure by any person other than the intended recipient is strictly prohibited and the person responsible may incur penalties.
Thank you!


draganddrop.zip
Message has been deleted

Luigi Ferraris

unread,
Apr 12, 2013, 6:31:50 AM4/12/13
to Karl, qtcon...@googlegroups.com
Il 12/04/2013 4.32, Karl ha scritto:
+1

I can confirm I have the same problem as Luigi using the QListWidget().  Even when dropping (trying to move) within the same list.

Please let me know if additional sample code is needed.

Karl
Hi Karl.
About "... same problem....": are you speaking about connected event?

If yes,
I think can be a Qt problem, because (googling) I found several blog about this problem (and they are using C++ language without binding for Qt). I have tested on Qt 5.0.1 and the problem still the same.
So, or there are problems with Qt (general speaking) or is a Windows/QtLibrary problem (some *nix user can do a test using connected event to catch something while drag&drop is performed?) or I'm doing some mistake or I'm losing piece of code (to setting object in a right way).

If not: d&d (copyaction or moveaction) it doesn't works with QListWidget?

Luigi

Karl

unread,
Apr 13, 2013, 6:50:16 AM4/13/13
to qtcon...@googlegroups.com, Karl, luigfe...@gmail.com
Whoops,

sorry my mistake.  I did not read that Pritpal has fixed it in the current hbqt version.  I will download and try it again and will let you know.

Karl

Karl

unread,
Apr 20, 2013, 7:01:13 AM4/20/13
to qtcon...@googlegroups.com, Karl, luigfe...@gmail.com
Works fine with the current hbqt version, now supporting:

  ::list:setDefaultDropAction( Qt_MoveAction )

Thanks to Pritpal ;)
 Karl

Reply all
Reply to author
Forward
0 new messages