本文整理汇总了C++中QDrag::exec方法的典型用法代码示例。如果您正苦于以下问题:C++ QDrag::exec方法的具体用法?C++ QDrag::exec怎么用?C++ QDrag::exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDrag
的用法示例。
在下文中一共展示了QDrag::exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startDrag
// this is reimplemented from QAbstractItemView::startDrag()
void ScreenSetupView::startDrag(Qt::DropActions)
{
QModelIndexList indexes = selectedIndexes();
if (indexes.count() != 1)
return;
QMimeData* pData = model()->mimeData(indexes);
if (pData == NULL)
return;
QPixmap pixmap = *model()->screen(indexes[0]).pixmap();
QDrag* pDrag = new QDrag(this);
pDrag->setPixmap(pixmap);
pDrag->setMimeData(pData);
pDrag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2));
if (pDrag->exec(Qt::MoveAction, Qt::MoveAction) == Qt::MoveAction)
{
selectionModel()->clear();
// make sure to only delete the drag source if screens weren't swapped
// see ScreenSetupModel::dropMimeData
if (!model()->screen(indexes[0]).swapped())
model()->screen(indexes[0]) = Screen();
else
model()->screen(indexes[0]).setSwapped(false);
}
}
示例2: mouseMoveEvent
void BookmarksToolBar::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton)) {
QToolBar::mouseMoveEvent(event);
return;
}
if ((event->pos() - m_dragStartPosition).manhattanLength()
< QApplication::startDragDistance()) {
QToolBar::mouseMoveEvent(event);
return;
}
QAction *action = actionAt(m_dragStartPosition);
QModelIndex index = this->index(action);
if (!index.isValid()) {
QToolBar::mouseMoveEvent(event);
return;
}
QString title = index.data().toString();
QUrl url = index.data(BookmarksModel::UrlRole).toUrl();
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData();
mimeData->setText(title);
mimeData->setUrls(QList<QUrl>() << url);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
示例3: mouseMoveEvent
void TabButton::mouseMoveEvent(QMouseEvent *e){
if (!isLeftBtnHold){
QPushButton::mouseMoveEvent(e);
return;
}
QPixmap pxm = QPixmap::grabWidget(this, rect());
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
stream << pxm << QPoint(mapFromGlobal(QCursor::pos()));
QMimeData *mimeData = new QMimeData();
mimeData->setData("application/x-dnditemdata", data);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(pxm);
drag->setHotSpot(mapFromGlobal(QCursor::pos()));
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
e->accept();
}
示例4: mouseMoveEvent
void GParamLabel::mouseMoveEvent(QMouseEvent *event)
{
QLabel::mouseMoveEvent(event);
Qt::KeyboardModifiers modif = event->modifiers();
Qt::MouseButtons butts = event->buttons();
// from qt "drag & drop" page
if(butts != Qt::LeftButton || modif != Qt::NoModifier)
return;
if((event->pos() - m_DragStartPosition).manhattanLength() < QApplication::startDragDistance())
return;
if(!m_pParam)
return;
QDrag* drag = new QDrag(this);
// extrapolation from qt help: "Using Drag and Drop with Item Views"
QMimeData* mimeData = new QMimeData();
QByteArray encodedData;
// we store the UniqueSystemID() in the mime's "LabExe/parameter.single"
QDataStream streamParamName(&encodedData, QIODevice::WriteOnly);
QString paramUniqueID = m_pParam->UniqueSystemID();
// lets check that it is in the Param manager so that it can be used by whoever will read this ID
if(!GetParamFromParamManager(paramUniqueID)) {
qDebug() << paramUniqueID << " is not in the Param Manager";
}
if(paramUniqueID != "") {
streamParamName << paramUniqueID;
}
mimeData->setData("LabExe/parameter.single", encodedData);
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->exec(Qt::CopyAction);
}
示例5: mouseMoveEvent
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton) {
#if QT_VERSION >= 0x040500
int diffX = event->pos().x() - m_dragStartPos.x();
int diffY = event->pos().y() - m_dragStartPos.y();
#endif
if ((event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()
#if QT_VERSION >= 0x040500
&& diffX < 3 && diffX > -3
&& diffY < -10
#endif
) {
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QList<QUrl> urls;
int index = tabAt(event->pos());
QUrl url = tabData(index).toUrl();
urls.append(url);
mimeData->setUrls(urls);
mimeData->setText(tabText(index));
mimeData->setData(QLatin1String("action"), "tab-reordering");
drag->setMimeData(mimeData);
drag->exec();
}
}
QTabBar::mouseMoveEvent(event);
}
示例6: mouseMoveEvent
void Menu::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton && (event->pos() - m_dragStartPosition).manhattanLength() >= QApplication::startDragDistance() && activeAction() && activeAction()->data().type() == QVariant::ULongLong)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QByteArray data;
WId window = activeAction()->data().toULongLong();
data.resize(sizeof(WId));
memcpy(data.data(), &window, sizeof(WId));
mimeData->setData("windowsystem/winid", data);
drag->setMimeData(mimeData);
drag->setPixmap(activeAction()->icon().pixmap(32, 32));
close();
drag->exec();
}
KMenu::mouseMoveEvent(event);
}
示例7: startDrag
void ResourceListWidget::startDrag(Qt::DropActions supportedActions)
{
if (supportedActions == Qt::MoveAction)
return;
QListWidgetItem *item = currentItem();
if (!item)
return;
const QString filePath = item->data(Qt::UserRole).toString();
const QIcon icon = item->icon();
QMimeData *mimeData = new QMimeData;
const QtResourceView::ResourceType type = icon.isNull() ? QtResourceView::ResourceOther : QtResourceView::ResourceImage;
mimeData->setText(QtResourceView::encodeMimeData(type , filePath));
QDrag *drag = new QDrag(this);
if (!icon.isNull()) {
const QSize size = icon.actualSize(iconSize());
drag->setPixmap(icon.pixmap(size));
drag->setHotSpot(QPoint(size.width() / 2, size.height() / 2));
}
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
示例8: mouseMoveEvent
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
if(!(event->buttons() & Qt::LeftButton))
return;
if((event->pos() - drag_pos).manhattanLength() < DRAG_OFFSET)
return;
fn_begin;
event->accept();
QDrag *drag = new QDrag(this);
/*DEBUG*/
drag->setObjectName("drag");
connect(drag, SIGNAL(destroyed()), twutil, SLOT(dumpDestroyed()));
QMimeData *mimedata = new QMimeData();
QWidget *widget = currentWidget();
mimedata->setData("action", "window_drag");
drag->setMimeData(mimedata);
QPixmap pixmap = QPixmap::grabWidget(widget).scaledToWidth(
PIXMAP_MAXWIDTH(widget->width()), Qt::SmoothTransformation);
DragPixmap *dragpixmap = new DragPixmap(pixmap, PIXMAP_OPACITY, widget);
connect(drag, SIGNAL(destroyed()), dragpixmap, SLOT(deleteLater()));
dragpixmap->setObjectName("dragpixmap");
connect(dragpixmap, SIGNAL(destroyed()), twutil, SLOT(dumpDestroyed()));
dragpixmap->show();
drag->exec();
emit widgetDnD(currentWidget(), drag->target());
QTabBar::mouseMoveEvent(event);
fn_end;
}
示例9: startDrag
void ShapeView::startDrag(Qt::DropActions supportedActions)
{
QString key = currentItem()->data(Qt::UserRole).toString();
if (m_Shapes.contains(key))
{
int w = m_Shapes[key].width;
int h = m_Shapes[key].height;
ScribusDoc *m_Doc = new ScribusDoc();
m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
m_Doc->setPage(w, h, 0, 0, 0, 0, 0, 0, false, false);
m_Doc->addPage(0);
m_Doc->setGUI(false, m_scMW, 0);
int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset(), w, h, m_Doc->itemToolPrefs().shapeLineWidth, m_Doc->itemToolPrefs().shapeFillColor, m_Doc->itemToolPrefs().shapeLineColor, true);
PageItem* ite = m_Doc->Items->at(z);
ite->PoLine = m_Shapes[key].path.copy();
FPoint wh = getMaxClipF(&ite->PoLine);
ite->setWidthHeight(wh.x(),wh.y());
ite->setTextFlowMode(PageItem::TextFlowDisabled);
m_Doc->AdjustItemSize(ite);
ite->OldB2 = ite->width();
ite->OldH2 = ite->height();
ite->updateClip();
ite->ClipEdited = true;
ite->FrameType = 3;
m_Doc->m_Selection->addItem(ite, true);
ScElemMimeData* md = ScriXmlDoc::WriteToMimeData(m_Doc, m_Doc->m_Selection);
QDrag* dr = new QDrag(this);
dr->setMimeData(md);
dr->setPixmap(currentItem()->icon().pixmap(QSize(48, 48)));
dr->exec();
delete m_Doc;
}
}
示例10: startDrag
void ScriptTableView::startDrag(Qt::DropActions supportedActions)
{
QModelIndexList indexes = selectedIndexes();
for(int i = indexes.count() - 1 ; i >= 0; --i)
{
const QModelIndex &index = indexes.at(i);
if(!(index.flags() & Qt::ItemIsDragEnabled))
indexes.removeAt(i);
}
if(indexes.count() == 0)
return;
QMimeData *data = model()->mimeData(indexes);
if(!data)
return;
QRect rect;
QDrag *drag = new QDrag(this);
drag->setMimeData(data);
Qt::DropAction finalDefaultDropAction = Qt::IgnoreAction;
if(defaultDropAction() != Qt::IgnoreAction && (supportedActions & defaultDropAction()))
finalDefaultDropAction = defaultDropAction();
else if(supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
finalDefaultDropAction = Qt::CopyAction;
drag->exec(supportedActions, finalDefaultDropAction);
}
示例11: mouseMoveEvent
void ToolButton::mouseMoveEvent(QMouseEvent *event )
{
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
if( (event->pos() - startDragPosition).manhattanLength() < QApplication::startDragDistance() )
{
return;
}
/* gridLayout->removeWidget( this );
gridLayout->update();
qDebug() << "test";*/
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setText( "Drag and Drop" );
mimeData->setData( "number", QString::number( numeroDansLaListe ).toUtf8() );
drag->setMimeData( mimeData );
drag->setPixmap( this->icon().pixmap( 64, 64 ) );
event->accept();
drag->exec(Qt::MoveAction);
mainWindow->updateProduit();
}
示例12: mouseMoveEvent
void LXQtTaskButton::mouseMoveEvent(QMouseEvent* event)
{
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())
return;
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData());
QIcon ico = icon();
QPixmap img = ico.pixmap(ico.actualSize({32, 32}));
drag->setPixmap(img);
switch (parentTaskBar()->panel()->position())
{
case ILXQtPanel::PositionLeft:
case ILXQtPanel::PositionTop:
drag->setHotSpot({0, 0});
break;
case ILXQtPanel::PositionRight:
case ILXQtPanel::PositionBottom:
drag->setHotSpot(img.rect().bottomRight());
break;
}
sDraggging = true;
drag->exec();
// if button is dropped out of panel (e.g. on desktop)
// it is not deleted automatically by Qt
drag->deleteLater();
sDraggging = false;
QAbstractButton::mouseMoveEvent(event);
}
示例13: mouseMoveEvent
void GLWidget::mouseMoveEvent(QMouseEvent* event)
{
QQuickWidget::mouseMoveEvent(event);
if (event->isAccepted()) return;
if (event->modifiers() == Qt::ShiftModifier && m_producer) {
emit seekTo(m_producer->get_length() * event->x() / width());
return;
}
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - m_dragStart).manhattanLength() < QApplication::startDragDistance())
return;
if (!MLT.producer() || !MLT.isClip())
return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setData(Mlt::XmlMimeType, MLT.XML().toUtf8());
drag->setMimeData(mimeData);
mimeData->setText(QString::number(MLT.producer()->get_playtime()));
if (m_frameRenderer && !m_glslManager && m_frameRenderer->getDisplayFrame().is_valid()) {
Mlt::Frame displayFrame(m_frameRenderer->getDisplayFrame().clone(false, true));
QImage displayImage = MLT.image(&displayFrame, 45 * MLT.profile().dar(), 45).scaledToHeight(45);
drag->setPixmap(QPixmap::fromImage(displayImage));
}
drag->setHotSpot(QPoint(0, 0));
drag->exec(Qt::LinkAction);
}
示例14: mousePressEvent
void Context::mousePressEvent(QMouseEvent *e) {
// Start dragging
if(e->button() == Qt::LeftButton) {
if(verbose) std::clog << "setOC: Start dragging" << std::endl;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
bool gotWidget = false;
mimeData->setData("photo/menuitem","someaction");
drag->setMimeData(mimeData);
for(int i = 0; i < allTiles.length(); ++i) {
ContextTile *tile = allTiles.at(i);
// Take the tile
if(tile->geometry().contains(e->pos()) && e->pos().x() < tile->x()+tile->dragLabel->x()+tile->dragLabel->width()) {
drag->setPixmap(QPixmap::grabWidget(allTiles.at(i)));
oldIndex = lay->indexOf(allTiles.at(i));
gotWidget = true;
break;
}
}
if(gotWidget)
drag->exec();
}
}
示例15: mousePressEvent
void bottom_label::mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton) {
QDrag* drag = new QDrag(this);
//const QPixmap *pPixmap = pixmap();
// drag->setPixmap(*pPixmap); //ÕâÀïÉèÖÃÍÏקʱ¸úËæÊó±êµÄͼƬ
//int w=pPixmap->size().width();
//int h=pPixmap->size().height();
//QPoint t;
//t.setX(w);
//t.setY(h);
// drag->setHotSpot(t); //ÉèÖøúËæͼƬµÄÖÐÐĵã
QMimeData *mimeData = new QMimeData;
QString send_mes = QString::number(id);
send_mes += "|2";
mimeData->setText(send_mes);
drag->setMimeData(mimeData);
//drag->setPixmap(iconPixmap);
Qt::DropAction dropAction = drag->exec();
drag->start(Qt::MoveAction);
}
}