QTREEWIDGET子分类,停止下降指示器显示给定有不必要的DropIndicatorPosition
QTreeWidget sub classing, stop drop indicator from showing given unwanted dropIndicatorPosition
我有以下问题。当我不想完成Drop事件时,我需要阻止Drop指示器出现,这是在DropIndIcatorPosition((返回QAbstractItemView::BelowItem
或QAbstractItemView::AboveItem
上的条件。现在,我子类QTreeWidget
,并具有以下dropEvent
的实现。
void SubClassedQTreeWidget::dropEvent(QDropEvent *event) {
DropIndicatorPosition position = dropIndicatorPosition();
if( position != QAbstractItemView::BelowItem && position != QAbstractItemView::AboveItem ){
// exit since we don't care for other types of drop events
return;
}
QTreeWidget::dropEvent(event);
}
我想这样做,以停止视觉指示,表明出现任何下降都可能发生。我只希望在黑线之间出现。我已经尝试重新实现dragMoveEvent
,但是通过:
DropIndicatorPosition position = dropIndicatorPosition();
setDropIndicatorShown(!(position != QAbstractItemView::BelowItem && position != QAbstractItemView::AboveItem));
实际上什么也没做,我希望某种方法不必以每种方式执行逻辑。
看来我抓住了你想要的东西。我以前的答案仅适用于列表。
要防止文件夹周围的绘画盒,您可以使用类似的东西:
void TreeView::paintEvent( QPaintEvent * event )
{
DropIndicatorPosition position = dropIndicatorPosition();
setDropIndicatorShown( position == QAbstractItemView::BelowItem || position == QAbstractItemView::AboveItem );
base_t::paintEvent( event );
setDropIndicatorShown( true );
}
并防止在它们上掉落(并在它们上面绘制一个禁止的光标(:
void TreeView::dragMoveEvent( QDragMoveEvent * event )
{
base_t::dragMoveEvent( event );
DropIndicatorPosition position = dropIndicatorPosition();
if ( position != QAbstractItemView::BelowItem && position != QAbstractItemView::AboveItem ) {
event->ignore();
}
}
但我不明白你为什么需要那个奇怪的事情。
您应该覆盖QAbstractItemModel::flags
,然后将Qt::ItemIsDropEnabled
标志添加到可以用作Drop目标的项目中。
相关文章:
- 用callgrind追踪不必要的副本
- 密码登录程序将永远循环并显示不正确的结果
- 不必要的C++代码最终会出现在我完成的程序中吗?
- 总和的不必要行为C++?
- C++:将初始化的对象传递给另一个类的构造函数;需要不必要的构造函数吗?
- 在这种情况下,使用 string_view 是否会导致不必要的字符串复制?
- std::mutex::lock() 产生奇怪(和不必要的)ASM 代码
- gdb映射显示不正确的成员变量
- 如何在插入排序中使用 replace() 使语句变得不必要
- C 包装器C++库周围没有不必要的头文件
- 使用带有诅咒库的 stdscr 创建窗口,在边框而不是线条中显示不需要的笑脸字符
- 编译器是否消除了不必要的原子?
- 在 c++ 中不必要的包含
- 使用 C++ 中的运算符重载显示不正确的结果
- 尝试使用 ifstream 读取数据后显示不正确的数字
- 对于第二个本机函数,显示不舒适的LinkError:未针对.stringfromjni2()找到实现
- "Time"库形式 Arduino 显示不正确的值
- GCC为AVR上的简单ISR产生不必要的寄存器推送
- 等效的 UTF8 显示不正确
- QTREEWIDGET子分类,停止下降指示器显示给定有不必要的DropIndicatorPosition