Why can't I see the drop indicator in QTableView?

I use drag and drop in my QTableView(works). However, I do not see a drop indicator. I should see a line where it is supposed that a drop should be inserted, right? At least here they say so.

My init is pretty standard.

    // see model for implementing logic of drag
    this->viewport()->setAcceptDrops(allowDrop);
    this->setDragEnabled(allowDrag);
    this->setDropIndicatorShown(true);
    this->m_model->allowDrop(allowDrop);

I have no idea why I do not see the indicator. Maybe the reason is that the stylesheet is used with views. However, I have disabled the stylesheet and still do not see it.

The view uses whole lines to select, but not sure if this is causing the problem. So any hint is appreciated.

- Change -

As in the comment below, I tried all the selection modes: single, multiple or advanced, without a visual effect. Also tried a cell instead of selecting a row, again no improvement.

- Change 2 -

Another example style proxy is currently being evaluated , similar to the one below, originally referenced here.

- Related -

Override indicator joining QTreeView
To select an entire row when you move the mouse in a QTableWidget: Qt5
https://forum.qt.io/topic/12794/mousehover-entire-row-selection-in-qtableview/7
qaru.site/questions/1644175/ ...

+4
source share
1 answer

, , . IIRC, SO.

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());
    }
};

:

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);
        }
    }
};
+1

All Articles