QTablewidget drop without creating new rows

依然范特西╮ 提交于 2019-12-01 12:32:04

A fast hack using an event filter (could need some tweaks):

What you do this is ignore any drop on the checkbox column. So it should be enough to disable row creation.

bool yourWidget::eventFilter(QObject *a_object, QEvent *a_event) 
  {
  bool result = false;
  if ((a_object == table->viewport()) && (a_event->type() == QEvent::Drop)) 
  {
     QDropEvent *p_drop_event = static_cast<QDropEvent *>(a_event);
     QPoint pos = p_drop_event->pos();
     QModelIndex new_index = table->indexAt(pos);
     if (new_index.column() == YOUR COLUMN HERE)
     {
       // Ignore drop event
       p_drop_event->setDropAction(Qt::IgnoreAction);
       p_drop_event->accept();
       return true;
     }
     else
     {
       // Allow drop
       return false;
     }

  }
return QObject::eventFilter(a_object, a_event);
}

Info about eventFilters:

Event Filters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!