Greeting:

Given this code how cooperation could implement drag drop between your item to be relocated within the Qtablewindget?.

and has implemented other drag drop objects, but not the same.

Thanks



Qt Code:
  1. Reproductor::Reproductor(QWidget *parent): QTableWidget(parent)
  2.  
  3.  
  4. {
  5. setDragDropOverwriteMode(false);
  6.  
  7. setDragEnabled(true);
  8.  
  9.  
  10. this->setAcceptDrops(true);
  11. this->setDropIndicatorShown(true);
  12. this->viewport()->setAcceptDrops(true);
  13.  
  14. setDragDropMode(QAbstractItemView::InternalMove);
  15.  
  16. this->setSelectionMode(QAbstractItemView::SingleSelection); //seleccionamos en una linea todas las columnas
  17. this->horizontalHeader()->setMovable(false); //evita cambiar las columnas
  18. this->horizontalHeader()->setResizeMode(QHeaderView::Fixed); //evita redimensionar las columnas
  19. this->setEditTriggers(QAbstractItemView::NoEditTriggers);
  20.  
  21.  
  22.  
  23.  
  24.  
  25. //funciones micelaneas
  26.  
  27. w_MiceAudio = new MiceAudio;
  28.  
  29.  
  30.  
  31.  
  32. }
  33. //*****************************************************************************
  34. Reproductor::~Reproductor(){
  35.  
  36.  
  37. delete w_MiceAudio;
  38. }
  39.  
  40. /*
  41.   -------------------------------------------------
  42.  Evento resize
  43.   --------------------------------------------------
  44.   */
  45.  
  46. void Reproductor::resizeEvent( QResizeEvent *event){
  47.  
  48.  
  49. //damos forma a las columnas
  50. int ancho = this->width();
  51.  
  52. this->setColumnWidth(0,20);
  53. this->setColumnWidth(2,90);
  54. this->setColumnWidth(1,ancho- 130);
  55.  
  56. // QMessageBox msgBox;
  57. // msgBox.setText("The document has been modified.");
  58. // msgBox.exec();
  59.  
  60. this->setColumnHidden(3, true); //ocultamos columnas segundos
  61. this->setColumnHidden(4, true); //ocultamos columnas fichero
  62.  
  63.  
  64. }
  65.  
  66. /*
  67.   -------------------------------------------------
  68.  Evento dop
  69.   --------------------------------------------------
  70.   */
  71.  
  72.  
  73. void Reproductor::dropEvent(QDropEvent *event)
  74. {
  75.  
  76.  
  77.  
  78.  
  79. if (event->mimeData()->hasFormat("text/uri-list")){
  80.  
  81.  
  82. QList<QUrl> urls = event->mimeData()->urls();
  83.  
  84.  
  85. QString fileName;
  86.  
  87.  
  88. for (int i = 0; i < urls.size(); ++i) {
  89. //qDebug() << "Original: " << fileName; c:/
  90. //qDebug() << "As URL: " << QUrl::fromLocalFile(fileName);
  91. //qDebug() << "Result: " << QDir::toNativeSeparators(fileName); c:\
  92.  
  93. //qDebug() << "total: " << urls.size();
  94.  
  95. fileName = urls.at(i).toLocalFile();
  96. QFileInfo NombreCorto(fileName);
  97.  
  98. const int currentRow = this->rowCount();
  99. this->setRowCount(currentRow + 1);
  100.  
  101. this->setItem(currentRow, 0, new QTableWidgetItem(fileName));
  102. this->setItem(currentRow, 1, new QTableWidgetItem(NombreCorto.fileName())); //nombre de la cancion
  103.  
  104. this->setItem(currentRow, 2, new QTableWidgetItem(w_MiceAudio->StreamFormato(fileName)));// duracion con formato
  105. this->item(currentRow, 2 )->setTextAlignment(Qt::AlignRight); // justificamos a la derecha el tiempo
  106.  
  107. //this->setItem(currentRow, 3, new QTableWidgetItem(FicheroTiempo(fileName)));// duracion en segundos
  108. this->setItem(currentRow, 4, new QTableWidgetItem(fileName));// direccion paht del fichero
  109.  
  110. }
  111.  
  112. }
  113.  
  114.  
  115. this->setFocus();
  116.  
  117.  
  118. }
  119.  
  120. //**************************************************************************************
  121.  
  122. void Reproductor::dragEnterEvent(QDragEnterEvent *event)
  123. {
  124.  
  125.  
  126. if (event->mimeData()->hasFormat("text/uri-list")){
  127. event->acceptProposedAction();
  128. return;
  129. }
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. }
  139. //******************************************************************************************
  140.  
  141. void Reproductor::dragMoveEvent(QDragMoveEvent *event)
  142. {
  143.  
  144.  
  145.  
  146.  
  147. }
  148.  
  149. void Reproductor::mousePressEvent(QMouseEvent *event)
  150. {
  151.  
  152.  
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161. void Reproductor::mouseMoveEvent(QMouseEvent *event)
  162. {
  163.  
  164. }
To copy to clipboard, switch view to plain text mode