Seite 1 von 1

QDrag hotSpot position von QListWidgetItem problem

Verfasst: 12. April 2008 10:12
von patrik08
Einen bild zu "Draggen" kommt bei mir nicht genau an in eine QListWidget
sondern sieht aus wie eine random position ...
Das bild verschiebt sich jedesmal von eine ungleiche position warum.

Leider hat QListWidgetItem nicht pos() wie kann ich die position trodtzdem bekommen...

dok sagt nur....

void QDrag::setHotSpot ( const QPoint & hotspot )
Sets the position of the hot spot relative to the top-left corner of the pixmap used to the point specified by hotspot.


Code: Alles auswählen

void mousePressEvent(QMouseEvent *event)
{
   if (enableout) {
     QListWidgetItem *child = itemAt(event->pos());
     if (!child) {
     return;  
     }
     /* IcoLine = hotel attribut icon mit beschreibung in 6 sprachen und
     int kategorie int id  + pixmap 30x30 */
     IcoLine Io = child->data(Qt::UserRole).value<IcoLine>();
     /* TabIcone liste von IcoLine */
     TabIcone dd;
     dd.all_lines.append(Io);
     
     QList<QListWidgetItem *> tutti = selectedItems();
     
     for (int i=0; i<tutti.size(); i++) {
        QListWidgetItem *pane = tutti[i];
        IcoLine Iter = pane->data(Qt::UserRole).value<IcoLine>();
        dd.all_lines.append(Iter);
     }
     
     QString stream = SaveTabelicon(dd); /* QDataStream zu toBase64 fuer sql*/
     QMimeData *mimeData = new QMimeData;
     mimeData->setData("application/x-atticonhotel",stream.toUtf8());
     
     QDrag *drag = new QDrag(this);
     drag->setMimeData(mimeData);
     drag->setPixmap(Io.pix());
     drag->setHotSpot(event->pos() - QPoint(5,5) ); //////  
     
     if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
          qDebug() << "### drag move it " << Io.id();
     }
     
     }
     
   QListWidget::mousePressEvent(event);
}