Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 拖放;在QTreeView中删除隐藏的QStandardItemModel列_C++_Qt_Drag And Drop_Qtreeview_Qstandarditemmodel - Fatal编程技术网

C++ 拖放;在QTreeView中删除隐藏的QStandardItemModel列

C++ 拖放;在QTreeView中删除隐藏的QStandardItemModel列,c++,qt,drag-and-drop,qtreeview,qstandarditemmodel,C++,Qt,Drag And Drop,Qtreeview,Qstandarditemmodel,在QTreeView中,我希望通过拖放来复制周围的行。相应的拖放设置如下所示: this->setDragDropMode( QAbstractItemView::DragDrop ); this->setDropIndicatorShown( true ); 这对于由QTreeView可视化的基础QStandardItemModel的列非常有效。但并非模型的所有列都是可视化的(请参见): void MyViewClass::columnCountChanged(int p_nOl

在QTreeView中,我希望通过拖放来复制周围的行。相应的拖放设置如下所示:

this->setDragDropMode( QAbstractItemView::DragDrop );
this->setDropIndicatorShown( true );
这对于由QTreeView可视化的基础QStandardItemModel的列非常有效。但并非模型的所有列都是可视化的(请参见):

void MyViewClass::columnCountChanged(int p_nOldCount,int p_nNewCount)
{
QTreeView::columnCountChanged(p_nOldCount,p_nNewCount);
对于(int i=MyViewClass::m_nColumnType;i
当QTreeView未显示所有列时,如何在QTreeView中通过拖放复制QStandardItemModel的整行?找到了解决方案:

必须继承/实现QAbstractModel功能:

  • 虚拟QMimeData*mimeData(常量QModelIndexList和索引)常量
  • 虚拟bool dropMimeData(常量qimedata*p_grData,Qt::DropAction p_grAction,int p_nRow,int p_nColumn,常量QModelIndex&p_grParentIdx)
  • 虚拟QStringList mimeTypes()常量
而mimeData需要对数据进行编码,dropMimeData需要对数据进行解码,并需要插入一个包含拖动数据的新行/列

    void MyViewClass::columnCountChanged(int p_nOldCount , int p_nNewCount )
    {
    QTreeView::columnCountChanged( p_nOldCount, p_nNewCount );

    for ( int i = MyViewClass::m_nColumnType; i < p_nNewCount; ++i )
    {
        setColumnHidden( i, true );
    }
}