QListWidget拖放项从Symbian上的列表中消失 [英] QListWidget drag and drop items disappearing from list on Symbian

查看:129
本文介绍了QListWidget拖放项从Symbian上的列表中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法实现带有自定义项目的QListWidget,可以通过拖放对其进行重新排序。问题是当我快速双击(很短的拖放)项目时,该项目有时会从QListWidget中消失。



这是构造函数我的小部件:

  ListPopisiDragDrop :: ListPopisiDragDrop(QWidget * parent):
QListWidget(parent)
{
setSelectionMode(QAbstractItemView :: SingleSelection);
setDragEnabled(true);
viewport()-> setAcceptDrops(true);
setDefaultDropAction(Qt :: MoveAction);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView :: InternalMove);
}

还有掉落事件:

  void ListPopisiDragDrop :: dropEvent(QDropEvent * event){

int startRow = currentIndex()。row();

QListWidget :: dropEvent(event);

int endRow = currentIndex()。row();

//更多代码...
}

自定义通过从QAbstractItemDelegate实现paint()和sizeHint()函数来制作商品。



当商品消失的问题发生时,dropEvent甚至都不会被调用。

>

我真的不知道发生了什么,如果我做错了什么。



谢谢!



编辑:
我正在运行该应用程序



Edit2:
如果我将此行添加到构造函数中:

  setDragDropOverwriteMode(true); 

列表中的项目仍然消失,但是有一个空白行。



Edit3:
我添加了以下代码以查看发生了什么:

  bool ListPopisiDragDrop :: event(QEvent * e){
qDebug()<<新事件,类型:<< e-> type()<<,listCount :<< this-> count();

QListWidget :: event(e);
}

在调用放置事件时,我还打印了放置事件。这给了我以下输出:

  ... 
[Qt Message]新事件,类型:12,listCount :2
[Qt消息]新事件,类型:12,listCount:2
[Qt消息]新事件,类型:68,listCount:2
[Qt消息] DROPEVENT
[Qt消息]新事件,类型:71,listCount:2
[Qt消息]新事件,类型:12,listCount:2
[Qt消息]新事件,类型:12,listCount: 2
[Qt消息]新事件,类型:68,listCount:2
[Qt消息] DROPEVENT
[Qt消息]新事件,类型:71,listCount:2
[Qt Message]新事件,类型:12,listCount:2
[Qt Message]新事件,类型:12,listCount:2
[Qt Message]新事件,类型:12,listCount:2
[Qt消息]新事件,类型:12
[Qt消息]新事件,类型:12,listCount:1
[Qt消息]新事件,类型:12 ,listCount:1
[Qt消息]新事件,类型:1,listCount:1
...

如您所见,在事件类型68之后,listCount从2更改为1(一项消失)。我仍然不明白问题出在哪里...



Edit4:
即使我没有使用自定义项目,我的行为也一样。



Edit5:
即使是[1]中的示例在移动设备上进行测试时,也具有相同的行为。

Qt版本可能有问题吗?我正在使用Qt for Symbian Devices版本4.6.3 ...



[1] http://www.java2s.com/Code/Cpp/Qt/QListWidgetdraganddrop ... ,或者当源和目标相同时,dropEvent中的更多代码会产生不好的效果(您可以检查startRow是否等于endRow,在这种情况下什么也不做)。



编辑:



该程序是否为您工作:

  #include< QApplication> 
#include< QListWidget>

int main(int argc,char ** argv)
{
QApplication a(argc,argv);

QListWidget lw;

for(int i = 1; i< 10; ++ i)
lw.addItem(new QListWidgetItem(QString( Item%1)。arg(i))) ;
lw.setDragEnabled(true); // ***
lw.viewport()-> setAcceptDrops(true); // ***
lw.setDefaultDropAction(Qt :: MoveAction); // ***
lw.setDropIndicatorShown(true); // ***

lw.setDragDropMode(QAbstractItemView :: InternalMove);

lw.show();

a.connect(& a,SIGNAL(lastWindowClosed()),& a,SLOT(quit()));
a.exec();
}

带有三颗星的行可以删除。该程序对我来说在Windows Q XP 4.7.1和VS2010编译的Windows XP上适用。


I'm having trouble implementing a QListWidget with custom items that can be reordered by dragging and dropping. The problem is when I make a fast double click (a very short drag&drop) on an item, the item sometimes disappears from the QListWidget.

This is the constructor for my Widget:

ListPopisiDragDrop::ListPopisiDragDrop(QWidget *parent) :
    QListWidget(parent)
{
    setSelectionMode(QAbstractItemView::SingleSelection);
    setDragEnabled(true);
    viewport()->setAcceptDrops(true);
    setDefaultDropAction(Qt::MoveAction);
    setDropIndicatorShown(true);
    setDragDropMode(QAbstractItemView::InternalMove);
}

also the drop event:

void ListPopisiDragDrop::dropEvent(QDropEvent *event){

    int startRow=currentIndex().row();

    QListWidget::dropEvent(event);

    int endRow=currentIndex().row();

    //more code...
}

Custom items are made by implementing paint() and sizeHint() functions from QAbstractItemDelegate.

When the problem with disappearing items happens, the dropEvent isn't even called.

I really don't know what is happening and if I'm doing something wrong. Any help is appreciated.

Thanks!

Edit: I'm running the application on a Symbian S60 5th edition phone.

Edit2: If I add this line to the constructor:

setDragDropOverwriteMode(true);

the item in the list still disappears, but an empty row stays in it's place.

Edit3: I've added this code to see what is happening:

bool ListPopisiDragDrop::event(QEvent *e){
    qDebug()<<"new event, type: "<<e->type()<<", listCount: "<<this->count();

    QListWidget::event(e);
}

I've also printed "drop event" when the drop event is called. This gives me the following output:

...
[Qt Message] new event, type:  12 , listCount:  2 
[Qt Message] new event, type:  12 , listCount:  2 
[Qt Message] new event, type:  68 , listCount:  2 
[Qt Message] DROPEVENT 
[Qt Message] new event, type:  71 , listCount:  2 
[Qt Message] new event, type:  12 , listCount:  2 
[Qt Message] new event, type:  12 , listCount:  2 
[Qt Message] new event, type:  68 , listCount:  2 
[Qt Message] DROPEVENT 
[Qt Message] new event, type:  71 , listCount:  2 
[Qt Message] new event, type:  12 , listCount:  2 
[Qt Message] new event, type:  12 , listCount:  2 
[Qt Message] new event, type:  12 , listCount:  2 
[Qt Message] new event, type:  68 , listCount:  2 
[Qt Message] new event, type:  12 , listCount:  1 
[Qt Message] new event, type:  12 , listCount:  1 
[Qt Message] new event, type:  1 , listCount:  1
...

As you can see, after event type 68, the listCount changes from 2 to 1 (one item disappears). I'm still not getting where the problem is...

Edit4: I'm having the same behavior even when I'm not using custom items. Still can't figure out what's wrong.

Edit5: Even the example from [1] has the same behavior when tested on the mobile device. Could the Qt version be a problem? I'm using Qt for Symbian Devices version 4.6.3...

[1]http://www.java2s.com/Code/Cpp/Qt/QListWidgetdraganddrop.htm

解决方案

I can think of 2 reasons for this behaviour: the signal itemDoubleClicked is handled somewhere in your QListWidget and does something unintendet, or your "more code" in dropEvent does something bad when source and destination are the same (you could check if startRow is equal to endRow and do nothing in this case).

Edit:

Does this program work for you:

#include <QApplication>
#include <QListWidget>

int main(int argc, char **argv)
{
    QApplication a(argc, argv);

    QListWidget lw;

    for(int i = 1; i < 10; ++i)
        lw.addItem(new QListWidgetItem(QString("Item %1").arg(i)));
    lw.setDragEnabled(true); // ***
    lw.viewport()->setAcceptDrops(true); // ***
    lw.setDefaultDropAction(Qt::MoveAction); // ***
    lw.setDropIndicatorShown(true); // ***

    lw.setDragDropMode(QAbstractItemView::InternalMove);

    lw.show();

    a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    a.exec();
}

Lines with three stars can be deleted. This program works for me on Windows XP with Qt 4.7.1, compiled with VS2010.

这篇关于QListWidget拖放项从Symbian上的列表中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆