Hi,

I'am working on a way to visualize the zValue hierarchy of PolygonItems in my scene. To do this I want to use the ListView which supports interaction with its items like moving. I need the behavior where one list element(item) can be moved down/up to a new index position and inserted on that postion while other items are pushed to free the space.. I have experimented with the ListView but apparently Im doing something wrong because the only behavior I get is CopyAction, istead I need the MoveAction which wont work.. I have attached a small example where You can see what I mean.

How do I get the MoveAction to work?

Regards,
Dave
import com.trolltech.qt.core.*;
import com.trolltech.qt.core.Qt.DropAction;
import com.trolltech.qt.core.Qt.DropActions;
import com.trolltech.qt.gui.*;

public class MyMainWindow extends QMainWindow {

    public QListView listView;
    private QStandardItemModel model;
    
    public MyMainWindow() {

        listView = new QListView(this);
        
        setupModel();
        setupViews();

        setCentralWidget(listView);
    }

    public static void main(String args[]) {
        QApplication.initialize(args);

        MyMainWindow myMainWindow = new MyMainWindow();
        myMainWindow.show();

        QApplication.exec();
    }
    
    
    private void setupModel() {

        model = new QStandardItemModel(){
                
                public Qt.DropActions supportedDropActions(){
                        return new Qt.DropActions(Qt.DropAction.MoveAction); 
//Qt.DropAction.CopyAction
                }
                
                public boolean dropMimeData(QMimeData data, Qt.DropAction 
action, int row, int column, QModelIndex parent){
                        System.out.println("row "+row+" col "+column);
                        return super.dropMimeData(data, action, row, column, 
parent);
                }
                
                public Qt.ItemFlags flags(QModelIndex index)
                {
                        return new Qt.ItemFlags(Qt.ItemFlag.ItemIsDragEnabled, 
Qt.ItemFlag.ItemIsDropEnabled, Qt.ItemFlag.ItemIsSelectable,  
Qt.ItemFlag.ItemIsEnabled);
                }
        };
        
        model.setHeaderData(0, Qt.Orientation.Horizontal, tr("Label"));
        model.appendRow(new QStandardItem("Holand"));
        model.appendRow(new QStandardItem("Turkey"));
        model.appendRow(new QStandardItem("Italy"));
        model.appendRow(new QStandardItem("Spain"));
        model.appendRow(new QStandardItem("Russia"));
        

    }
    
    private void setupViews() {

        listView.setModel(model);

        QItemSelectionModel selectionModel = new QItemSelectionModel(model);
        listView.setSelectionModel(selectionModel);
        listView.setDragEnabled(true);
        listView.setDropIndicatorShown(true);
        listView.setAcceptDrops(true);
        listView.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove);
        listView.setDragDropMode(QAbstractItemView.DragDropMode.DragDrop);
        
listView.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection);
        
listView.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows);
        listView.setSelectionRectVisible(false);
        listView.setMovement(QListView.Movement.Free);
        listView.setSpacing(4);

    }

}
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to