2016-06-13 2 views
4

QTableView (작동)에 드래그 앤 드롭을 사용합니다. 그러나 드롭 인디케이터가 보이지 않습니다. 방울이 삽입되어야하는 선을보아야합니다. 그렇지 않아야합니까? 적어도 here 그들은 그렇게 말합니다.QTableView에서 드롭 표시기가 보이지 않는 이유는 무엇입니까?

내 init은 거의 표준입니다.

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

표시기가 표시되지 않는 이유는 알 수 없습니다. 스타일 시트가 뷰와 함께 사용되며 그 이유가 될 수 있습니다. 그러나 나는 스타일 시트를 사용하지 않았고 여전히 그것을 보지 못했다.

뷰가 전체 행을 사용하여 문제를 일으키는 지 확실하지 않습니다. 그래서 어떤 힌트를 주셔서 감사합니다.

- 편집 - 아래의 코멘트로, 모든 선택 모드 시도

: 단일 다중 또는 확장, 아니 시각적 효과를. 행 선택 대신에 셀을 시도해 보았습니다.

- 편집 2 -

현재 원래 참조 아래 하나, here

유사 another style proxy example, 평가 - 관련 -

QTreeView draw drop indicator
How to highlight the entire row on mouse hover in QTableWidget: Qt5
https://forum.qt.io/topic/12794/mousehover-entire-row-selection-in-qtableview/7

+1

컨텍스트의 불분명하지만 : 그것은뿐만 아니라 선택 모드와 관련이있다. 설정은 무엇입니까? 예 : tableView-> setSelectionMode (QAbstractItemView :: ExtendedSelection); – AlexanderVX

+0

는 3 가지 모드를 모두 시도했습니다 : 단일, 다중, 확장 - 효과 없음 –

답변

1

나는 똑같은 문제에 직면했다. 나는 둘 다 나를 위해 일한 두 가지 옵션을 시도했다. IIRC, 도움은 SO에 대한 답변에서 왔습니다.

  • QTreeView을 서브 클래 싱하는 경우 해당 paintEvent() 메서드를 재정의 할 수 있습니다. 기본적으로 drawTree() 메서드와 paintDropIndicator() 메서드를 호출합니다 (후자는 QAbstractItemView 개인 클래스의 일부 임).

당신은 당신의 paintEvent()에서 drawTree()를 호출 할 수 있습니다, 그것은뿐만 아니라 표시를 기본 드래그를 무시하고 드롭해야

class MyTreeView : public QTreeView 
{ 
public: 
    explicit MyTreeView(QWidget* parent = 0) : QTreeView(parent) {} 

    void paintEvent(QPaintEvent * event) 
    { 
     QPainter painter(viewport()); 
     drawTree(&painter, event->region()); 
    } 
}; 
  • 다른 방법은 QProxyStyle를 서브 클래스와 drawPrimitive() 메서드를 재정의하는 것입니다. 요소 인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); 
     } 
    } 
}; 
+0

시도해 보았습니다. QProxyStyleApproach를 사용했습니다. draw 선 부분이 호출되는 것을 볼 수 있지만, 내 경우에는 시각적 인 영향을주지 않습니다. 이전처럼 보입니다. 다른 가상 구현 인 doc.qt.io/qt-5/qproxystyle을 시도 할 것입니다.html # QProxyStyle 전달 된 rect는 항상 0x0 크기 인 것처럼 보입니다. –

+0

Here https://forum.qt.io/topic/62496/is-it-possible-for-a-qtableview-to-accept-a-drop-in-theempty-area-below-its-last- 행 (QProxyStyle')과 같은 방식으로 논의하지만,'QTableView'에는 적용 할 수없는 것 같습니다. –

관련 문제