PDA

View Full Version : Drag drop internal



valgaba
30th September 2010, 14:49
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




Reproductor::Reproductor(QWidget *parent): QTableWidget(parent)


{
setDragDropOverwriteMode(false);

setDragEnabled(true);


this->setAcceptDrops(true);
this->setDropIndicatorShown(true);
this->viewport()->setAcceptDrops(true);

setDragDropMode(QAbstractItemView::InternalMove);

this->setSelectionMode(QAbstractItemView::SingleSelectio n); //seleccionamos en una linea todas las columnas
this->horizontalHeader()->setMovable(false); //evita cambiar las columnas
this->horizontalHeader()->setResizeMode(QHeaderView::Fixed); //evita redimensionar las columnas
this->setEditTriggers(QAbstractItemView::NoEditTriggers) ;





//funciones micelaneas

w_MiceAudio = new MiceAudio;




}
//************************************************** ***************************
Reproductor::~Reproductor(){


delete w_MiceAudio;
}

/*
-------------------------------------------------
Evento resize
--------------------------------------------------
*/

void Reproductor::resizeEvent( QResizeEvent *event){


//damos forma a las columnas
int ancho = this->width();

this->setColumnWidth(0,20);
this->setColumnWidth(2,90);
this->setColumnWidth(1,ancho- 130);

// QMessageBox msgBox;
// msgBox.setText("The document has been modified.");
// msgBox.exec();

this->setColumnHidden(3, true); //ocultamos columnas segundos
this->setColumnHidden(4, true); //ocultamos columnas fichero


}

/*
-------------------------------------------------
Evento dop
--------------------------------------------------
*/


void Reproductor::dropEvent(QDropEvent *event)
{




if (event->mimeData()->hasFormat("text/uri-list")){


QList<QUrl> urls = event->mimeData()->urls();


QString fileName;


for (int i = 0; i < urls.size(); ++i) {
//qDebug() << "Original: " << fileName; c:/
//qDebug() << "As URL: " << QUrl::fromLocalFile(fileName);
//qDebug() << "Result: " << QDir::toNativeSeparators(fileName); c:\

//qDebug() << "total: " << urls.size();

fileName = urls.at(i).toLocalFile();
QFileInfo NombreCorto(fileName);

const int currentRow = this->rowCount();
this->setRowCount(currentRow + 1);

this->setItem(currentRow, 0, new QTableWidgetItem(fileName));
this->setItem(currentRow, 1, new QTableWidgetItem(NombreCorto.fileName())); //nombre de la cancion

this->setItem(currentRow, 2, new QTableWidgetItem(w_MiceAudio->StreamFormato(fileName)));// duracion con formato
this->item(currentRow, 2 )->setTextAlignment(Qt::AlignRight); // justificamos a la derecha el tiempo

//this->setItem(currentRow, 3, new QTableWidgetItem(FicheroTiempo(fileName)));// duracion en segundos
this->setItem(currentRow, 4, new QTableWidgetItem(fileName));// direccion paht del fichero

}

}


this->setFocus();


}

//************************************************** ************************************

void Reproductor::dragEnterEvent(QDragEnterEvent *event)
{


if (event->mimeData()->hasFormat("text/uri-list")){
event->acceptProposedAction();
return;
}








}
//************************************************** ****************************************

void Reproductor::dragMoveEvent(QDragMoveEvent *event)
{




}

void Reproductor::mousePressEvent(QMouseEvent *event)
{


}







void Reproductor::mouseMoveEvent(QMouseEvent *event)
{

}