8 Star 26 Fork 15

zhangheyang/LVGLBuilder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
LVGLWidgetListView.cpp 1023 Bytes
一键复制 编辑 原始数据 按行查看 历史
CURTLab 提交于 2020-07-29 23:17 . Added preview when dragging a widget
#include "LVGLWidgetListView.h"
#include "LVGLWidgetModel.h"
#include <QMimeData>
#include <QDrag>
#include "LVGLCore.h"
LVGLWidgetListView::LVGLWidgetListView(QWidget *parent) : QListView(parent)
{
setDragEnabled(true);
setDragDropMode(QAbstractItemView::DragOnly);
}
void LVGLWidgetListView::startDrag(Qt::DropActions supportedActions)
{
const QModelIndexList indexes = selectedIndexes();
QMimeData *mimeData = model()->mimeData(indexes);
if (!mimeData->hasFormat("application/x-widget"))
return QListView::startDrag(supportedActions);
LVGLWidgetCast cast;
QByteArray encoded = mimeData->data("application/x-widget");
QDataStream stream(&encoded, QIODevice::ReadOnly);
stream >> cast.i;
LVGLWidget *widgetClass = cast.ptr;
QPixmap preview = widgetClass->preview();
if (!preview.isNull()) {
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(preview);
drag->setHotSpot({0, 0});
drag->exec(supportedActions);
} else {
QListView::startDrag(supportedActions);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangheyang/LVGLBuilder.git
git@gitee.com:zhangheyang/LVGLBuilder.git
zhangheyang
LVGLBuilder
LVGLBuilder
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385