Qt LISTVIEW中拖拽的疑问 (分不是问题,请高手指点下啊)

kkting 2009-04-21 05:55:43

想在listview中可以支持拖拽ITEM项,下面是实现代码
ui.listView->setSelectionMode(QAbstractItemView::ContiguousSelection);
ui.listView->setDragEnabled(true);
ui.listView->viewport()->setAcceptDrops(true);
ui.listView->setDropIndicatorShown(true);
ui.listView->setDragDropMode(QAbstractItemView::InternalMove);
这样设置后就可以实现拖拽功能了
问题是:
我把listview的实现模式改为ICON模式,添加了下面两行代码
ui.listView->setViewMode(QListView::IconMode);
ui.listView->setUniformItemSizes(true);
这时候拖拽功能就没用了,请大侠指点下这是怎么回事啊?
...全文
887 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
liliangbao 2009-04-22
  • 打赏
  • 举报
回复
帮顶~
  • 打赏
  • 举报
回复
不好意思,没看到你给我发的私信?

用dragEnabled()看,返回值是true
去掉了 ui.listView->setUniformItemSizes(true);
也不可以

我很奇怪,为什么listmodle可以,而iconmodle就不可以。
这个问题困扰我好久了,请帮帮忙,非常感谢。


你试过listmodle??
那我估计就是这样了,mannual写反了.

QListView::Static 0 The items cannot be moved by the user.
QListView::Free 1 The items can be moved freely by the user.


QListView::ListMode 0 The items are layed out using TopToBottom flow, with Small size and Static movement
QListView::IconMode 1 The items are layed out using LeftToRight flow, with Large size and Free movement



IconMode 本身就不支持拖拽
  • 打赏
  • 举报
回复
晕,难道是mannaul写反了.
你换成ListMode 模式看下.
kkting 2009-04-22
  • 打赏
  • 举报
回复
谢谢 hairetz!

代码:
ui.listView->setViewMode(QListView::IconMode);
ui.listView->setUniformItemSizes(true);

ui.listView->setSelectionMode(QAbstractItemView::ContiguousSelection);
ui.listView->setDragEnabled(true);
ui.listView->viewport()->setAcceptDrops(true);
ui.listView->setDropIndicatorShown(true);
ui.listView->setDragDropMode(QAbstractItemView::InternalMove);

用dragEnabled()看,返回值是true
去掉了 ui.listView->setUniformItemSizes(true);
也不可以
是哪里的原因呢?
kkting 2009-04-22
  • 打赏
  • 举报
回复
IconMode 本身就不支持拖拽

如果这样,想实现拖拽的话只有自己重新写过了
kkting 2009-04-22
  • 打赏
  • 举报
回复
恩,我试过了
改为listmode后就可以了
ui.listView->setViewMode(QListView::ListMode);

  • 打赏
  • 举报
回复
在后面dragEnabled ()看下,是不是改成false了.
  • 打赏
  • 举报
回复
QListView::Static 0 The items cannot be moved by the user.
QListView::Free 1 The items can be moved freely by the user.


QListView::ListMode 0 The items are layed out using TopToBottom flow, with Small size and Static movement
QListView::IconMode 1 The items are layed out using LeftToRight flow, with Large size and Free movement


ui.listView->setUniformItemSizes(true); 去掉看下.

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧