If you can read my code this QListWidget can drag drop multile items as icon.. and text
from attribute hotels sauna bar, ecc..
{
Q_OBJECT
//
public:
IconScroller
( bool enable
= false ,
QWidget* parent
= 0 ){
enableout = enable;
setAcceptDrops(true);
setDropIndicatorShown(false);
if (enable) {
setDragEnabled(true);
}
///////setIconSize ( QSize(80,80));
}
{
if (enableout) {
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>();
QPixmap dragicon
= Io.
pix().
scaledToWidth(Io.
pix().
width() * 3);
/* zoom it */ /* TabIcone liste von IcoLine */
TabIcone dd;
dd.all_lines.append(Io);
QList<QListWidgetItem *> tutti = selectedItems();
for (int i=0; i<tutti.size(); i++) {
IcoLine Iter = pane->data(Qt::UserRole).value<IcoLine>();
dd.all_lines.append(Iter);
}
QString stream
= SaveTabelicon
(dd
);
/* QDataStream zu toBase64 fuer sql*/ mimeData->setData("application/x-atticonhotel",stream.toUtf8());
drag->setMimeData(mimeData);
drag->setPixmap(dragicon);
///////drag->setHotSpot(event->pos() - ????? ); //////
/* make pixmap large and setHotSpot not need */
if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
qDebug() << "### drag move it " << Io.id();
}
}
}
{
///////qDebug() << "### dropEvent";
if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
QByteArray itemData
= event
->mimeData
()->data
("application/x-atticonhotel");
//////////qDebug() << "### dropEvent entra siiiiiiiiiiii ";
TabIcone liste = OpenTabelicon(daten);
emit AppendList(liste);
event->accept();
} else {
event->ignore();
}
}
{
qDebug() << "### dragEnterEvent ";
if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
qDebug() << "### dragEnterEvent si ";
event->acceptProposedAction();
} else {
event->ignore();
}
}
{
qDebug() << "### dragMoveEvent ";
if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
qDebug() << "### dragMoveEvent si ";
event->acceptProposedAction();
} else {
event->ignore();
}
}
bool enableout;
signals:
void AppendList(TabIcone);
public slots:
};
class IconScroller : public QListWidget
{
Q_OBJECT
//
public:
IconScroller( bool enable = false , QWidget* parent = 0 )
: QListWidget( parent )
{
enableout = enable;
setSelectionMode ( QAbstractItemView::ExtendedSelection );
setAcceptDrops(true);
setDropIndicatorShown(false);
if (enable) {
setDragEnabled(true);
}
///////setIconSize ( QSize(80,80));
}
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>();
QPixmap dragicon = Io.pix().scaledToWidth(Io.pix().width() * 3); /* zoom it */
/* 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(dragicon);
///////drag->setHotSpot(event->pos() - ????? ); //////
/* make pixmap large and setHotSpot not need */
if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
qDebug() << "### drag move it " << Io.id();
}
}
QListWidget::mousePressEvent(event);
}
void dropEvent(QDropEvent *event)
{
///////qDebug() << "### dropEvent";
if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
QByteArray itemData = event->mimeData()->data("application/x-atticonhotel");
//////////qDebug() << "### dropEvent entra siiiiiiiiiiii ";
QString daten = QString::fromUtf8(itemData.data());
TabIcone liste = OpenTabelicon(daten);
emit AppendList(liste);
event->accept();
} else {
event->ignore();
}
}
void dragEnterEvent(QDragEnterEvent *event)
{
qDebug() << "### dragEnterEvent ";
if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
qDebug() << "### dragEnterEvent si ";
event->acceptProposedAction();
} else {
event->ignore();
}
}
void dragMoveEvent(QDragMoveEvent *event)
{
qDebug() << "### dragMoveEvent ";
if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
qDebug() << "### dragMoveEvent si ";
event->acceptProposedAction();
} else {
event->ignore();
}
}
bool enableout;
signals:
void AppendList(TabIcone);
public slots:
};
To copy to clipboard, switch view to plain text mode
Bookmarks