Hor*_*ter 6 c++ qt qtableview qt5.6
我在我的QTableView
(作品)中使用拖放。但是,我没有看到任何下降指标。我应该看到一条应该插入水滴的线,不是吗?至少在这里他们是这么说的。
我的 init 非常标准。
// see model for implementing logic of drag
this->viewport()->setAcceptDrops(allowDrop);
this->setDragEnabled(allowDrag);
this->setDropIndicatorShown(true);
this->m_model->allowDrop(allowDrop);
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我看不到指标。样式表与视图一起使用,这可能是原因。但是,我已禁用样式表,但仍然看不到它。
该视图使用整行进行选择,不确定这是否会导致问题。所以任何提示表示赞赏。
- 编辑 -
根据下面的评论,尝试了所有选择模式:单、多或扩展,没有视觉效果。还尝试了单元格而不是行选择,同样没有改进。
-- 编辑 2 --
目前正在评估另一个样式代理示例,类似于下面的,最初引用here
- 有关的 -
QTreeView 绘制下拉指示器
如何在 QTableWidget 中突出显示鼠标悬停的整行:Qt5
https://forum.qt.io/topic/12794/mousehover-entire-row-selection-in-qtableview/7
https://stackoverflow。 com/a/23111484/356726
我遇到了同样的问题,我尝试了两种对我有用的选择。IIRC,帮助来自 SO 的答案。
QTreeView
,你可以重写它的paintEvent()方法。它默认调用drawTree()方法和paintDropIndicator()
一个方法(后者是QAbstractItemView
私有类的一部分)。drawTree()
您可以从您的调用paintEvent()
,它也应该覆盖默认的拖放指示器:
class MyTreeView : public QTreeView
{
public:
explicit MyTreeView(QWidget* parent = 0) : QTreeView(parent) {}
void paintEvent(QPaintEvent * event)
{
QPainter painter(viewport());
drawTree(&painter, event->region());
}
};
Run Code Online (Sandbox Code Playgroud)
QStyle::PE_IndicatorItemViewItemDrop
作为参数时,您可以按照自己的方式绘制它。代码如下所示:
class MyOwnStyle : public QProxyStyle
{
public:
MyOwnStyle(QStyle* style = 0) : QProxyStyle(style) {}
void drawPrimitive(PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
{
if (element == QStyle::PE_IndicatorItemViewItemDrop)
{
//custom paint here, you can do nothing as well
QColor c(Qt::white);
QPen pen(c);
pen.setWidth(1);
painter->setPen(pen);
if (!option->rect.isNull())
painter->drawLine(option->rect.topLeft(), option->rect.topRight());
}
else
{
// the default style is applied
QProxyStyle::drawPrimitive(element, option, painter, widget);
}
}
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1417 次 |
最近记录: |