当前位置: 首页>>代码示例>>C++>>正文


C++ QDrag::setPixmap方法代码示例

本文整理汇总了C++中QDrag::setPixmap方法的典型用法代码示例。如果您正苦于以下问题:C++ QDrag::setPixmap方法的具体用法?C++ QDrag::setPixmap怎么用?C++ QDrag::setPixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDrag的用法示例。


在下文中一共展示了QDrag::setPixmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mouseMoveEvent

void SiteIcon::mouseMoveEvent(QMouseEvent* e)
{
    if (!m_locationBar || e->buttons() != Qt::LeftButton) {
        ToolButton::mouseMoveEvent(e);
        return;
    }

    int manhattanLength = (e->pos() - m_dragStartPosition).manhattanLength();
    if (manhattanLength <= QApplication::startDragDistance()) {
        ToolButton::mouseMoveEvent(e);
        return;
    }

    const QUrl url = m_locationBar->webView()->url();
    const QString title = m_locationBar->webView()->title();

    if (url.isEmpty() || title.isEmpty()) {
        ToolButton::mouseMoveEvent(e);
        return;
    }

    QDrag* drag = new QDrag(this);
    QMimeData* mime = new QMimeData;
    mime->setUrls(QList<QUrl>() << url);
    mime->setText(title);
    mime->setImageData(icon().pixmap(16).toImage());

    drag->setMimeData(mime);
    drag->setPixmap(QzTools::createPixmapForSite(icon(), title, url.toString()));
    drag->exec();

    // Restore Down state
    setDown(false);
}
开发者ID:Acidburn0zzz,项目名称:qupzilla,代码行数:34,代码来源:siteicon.cpp

示例2: event

bool QtDNDTabBar::event(QEvent* event) {
	QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
	if (mouseEvent) {
		QWidget* childAtPoint = window()->childAt(mapTo(window(), mouseEvent->pos()));
		QtDNDTabBar* underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint);
		if (!underMouse && childAtPoint) {
			underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint->parent());
		}
		if (!underMouse && currentIndex() >= 0) {
			// detach and drag

			// stop move event
			QMouseEvent* finishMoveEvent = new QMouseEvent (QEvent::MouseMove, mouseEvent->pos (), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
			QTabBar::event(finishMoveEvent);
			delete finishMoveEvent;
			finishMoveEvent = NULL;

			// start drag
			QDrag* drag = new QDrag(this);
			QMimeData* mimeData = new QMimeData;

			// distinguish tab-reordering drops from other ones
			mimeData->setData("action", "application/tab-detach") ;
			drag->setMimeData(mimeData);

			// set drag image
			QRect rect = tabRect( currentIndex() );
#if QT_VERSION >= 0x050000
			QPixmap pixmap = grab(rect);
#else
			QPixmap pixmap = QPixmap::grabWidget(this, rect);
#endif
			QPixmap targetPixmap (pixmap.size ());
			QPainter painter (&targetPixmap);
			painter.setOpacity(0.9);
			painter.drawPixmap(0,0, pixmap);
			painter.end ();
			drag->setPixmap (targetPixmap);

			drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()));

			dragIndex = currentIndex();
			dragText = tabText(dragIndex);
			dragWidget = dynamic_cast<QTabWidget*>(parent())->widget(dragIndex);
			assert(dragWidget);
			dynamic_cast<QTabWidget*>(parent())->removeTab(currentIndex());
			Qt::DropAction dropAction = drag->exec();
			if (dropAction == Qt::IgnoreAction) {
				// aborted drag, put tab back in place
				// disable event handling during the insert for the tab to prevent infinite recursion (stack overflow)
				dragWidget->blockSignals(true);
				dynamic_cast<QTabWidget*>(parent())->insertTab(dragIndex, dragWidget, dragText);
				dragWidget->blockSignals(false);
			}
			return true;
		}
	}
	return QTabBar::event(event);
}
开发者ID:scopeInfinity,项目名称:swift,代码行数:59,代码来源:QtDNDTabBar.cpp

示例3: startDrag

void TreeView::startDrag(Qt::DropActions supportedActions)
{
	QModelIndex index = selectedIndexes().value(0);

	if (!index.isValid())
		return;

	QMimeData *data = model()->mimeData(QModelIndexList() << index);

	if (!data)
		return;
	QRect rect;
	QPixmap pixmap;
	QPoint point;
	{
		QAbstractItemDelegate *delegate = itemDelegate(index);
		QStyleOptionViewItemV4 option = viewOptions();
		option.locale = this->locale();
		option.locale.setNumberOptions(QLocale::OmitGroupSeparator);
		option.widget = this;
		option.state |= QStyle::State_Selected;
		option.rect = visualRect(index);
		point = option.rect.topLeft();
		option.rect.moveTo(0, 0);
		option.rect.setSize(delegate->sizeHint(option, index));
		rect = option.rect;
		pixmap = QPixmap(rect.size());
		pixmap.fill(Qt::transparent);
		QPainter painter(&pixmap);
		delegate->paint(&painter, option, index);
	}
	QDrag *drag = new QDrag(this);
	drag->setPixmap(pixmap);
	drag->setMimeData(data);
	point = QCursor::pos() - viewport()->mapToGlobal(point);
	drag->setHotSpot(point);
	//			drag->setHotSpot(QCursor::pos() - rect.topLeft());
	Qt::DropAction setDefaultDropAction = QAbstractItemView::defaultDropAction();
	Qt::DropAction defaultDropAction = Qt::IgnoreAction;
	if (setDefaultDropAction != Qt::IgnoreAction && (supportedActions & setDefaultDropAction))
		defaultDropAction = setDefaultDropAction;
	else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
		defaultDropAction = Qt::CopyAction;
	if (drag->exec(supportedActions, defaultDropAction) == Qt::IgnoreAction
			&& index.data(ItemTypeRole).toInt() == ContactType) {
		if (QWidget *widget = QApplication::topLevelAt(QCursor::pos())) {
			if (widget->window() == this->window())
				return;
		}
		Event ev("contact-list-drop",
				 QCursor::pos() - point,
				 index.data(BuddyRole));
		ev.send();
	}
	//			debug() << "DropAction" << drag->exec(supportedActions, defaultDropAction);
	//			if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction)
	//				d->clearOrRemove();
	//			{}
}
开发者ID:andrecurvello,项目名称:qutim,代码行数:59,代码来源:simplecontactlistview.cpp

示例4: QDrag

QDrag *DndFactory::createDrag( const Incidence::Ptr &incidence, QWidget *owner )
{
  QDrag *drag = new QDrag( owner );
  drag->setMimeData( createMimeData( incidence ) );
  drag->setPixmap( BarIcon( incidence->iconName() ) );

  return drag;
}
开发者ID:pvuorela,项目名称:kcalcore,代码行数:8,代码来源:dndfactory.cpp

示例5: plViewStartDrag

static inline void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & supportedActions )
{
    QDrag *drag = new QDrag( view );
    drag->setPixmap( QPixmap( ":/noart64" ) );
    drag->setMimeData( view->model()->mimeData(
        view->selectionModel()->selectedIndexes() ) );
    drag->exec( supportedActions );
}
开发者ID:BloodExecutioner,项目名称:vlc,代码行数:8,代码来源:views.cpp

示例6: startDrag

void ImageWindow::startDrag() {
    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData();
    QByteArray encodedData;
    QDataStream stream(&encodedData, QIODevice::WriteOnly);
    uintptr_t ptr = reinterpret_cast<uintptr_t>(this);
    stream << QVariant::fromValue(ptr);
    if(_imageView->mode() == ImageView::MODE_MOUSE) {
        mimeData->setData("application/detiqt.genericinterface.stdimgwnd", encodedData);
        drag->setPixmap(_imageView->pixmap().scaled(QSize(76,76), Qt::KeepAspectRatio, Qt::FastTransformation));
    }
    else {
        mimeData->setData("application/detiqt.genericinterface.stdimgwnd.copy", encodedData);
        drag->setPixmap(_imageView->pixmap().copy(_imageView->select()).scaled(QSize(76,76), Qt::KeepAspectRatio, Qt::FastTransformation));
    }
    drag->setMimeData(mimeData);
    drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2));
    drag->exec();
}
开发者ID:zakinster,项目名称:detiq-t,代码行数:19,代码来源:ImageWindow.cpp

示例7: slotDragSnapshot

void KSnapshot::slotDragSnapshot()
{
    QDrag *drag = new QDrag(this);

    drag->setMimeData(new QMimeData);
    drag->mimeData()->setImageData(snapshot);
    drag->mimeData()->setData("application/x-kde-suggestedfilename", QFileInfo(file_path_).fileName().toUtf8());
    drag->setPixmap(preview());
    drag->start();
}
开发者ID:Berrrry,项目名称:Qtqq,代码行数:10,代码来源:ksnapshot.cpp

示例8: startDrag

void GenomeVectorListView::startDrag(Qt::DropActions supportedActions)
{
	QDrag* drag = new QDrag(this);
	QMimeData* mimeData = new QMimeData;
	mimeData->setData("application/x-qabstractitemmodeldatalist", QByteArray::number(dragStartIndex.row()));
	drag->setMimeData(mimeData);
	drag->setPixmap(model()->data(dragStartIndex, Qt::DecorationRole).value<QPixmap>());
	drag->exec(supportedActions);
	selectionModel()->select(qobject_cast<GenomeVector*>(model())->selectedIndex(), QItemSelectionModel::ClearAndSelect);
}
开发者ID:ShadowKyogre,项目名称:qosmic,代码行数:10,代码来源:genomevectorlistview.cpp

示例9: mouseMoveEvent

void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if ( !m_enabled
            || QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length()
            < m_startDragDistance) {
        return;
    }

    emit dragStarted();

    QDrag *drag = new QDrag(event->widget());
    DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it.
    drag->setMimeData(dataCopy);

    if (!m_delegateImage.isNull()) {
        drag->setPixmap(QPixmap::fromImage(m_delegateImage));
    } else if (m_delegate) {
        // Render the delegate to a Pixmap
        QDeclarativeItem* item = qobject_cast<QDeclarativeItem *>(m_delegate->create(m_delegate->creationContext()));

        QGraphicsScene scene;
        scene.addItem(item);

        QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height());
        pixmap.fill(Qt::transparent);

        QPainter painter(&pixmap);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setRenderHint(QPainter::SmoothPixmapTransform);
        scene.render(&painter);
        painter.end();
        delete item;

        drag->setPixmap(pixmap);
    }

    drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); // TODO: Make a property for that

    //setCursor(Qt::OpenHandCursor);    //TODO? Make a property for the cursor

    Qt::DropAction action = drag->exec(m_supportedActions, m_defaultAction);
    emit drop(action);
}
开发者ID:KDE,项目名称:kde-runtime,代码行数:43,代码来源:DeclarativeDragArea.cpp

示例10: mouseMoveEvent

 void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
     if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton))
         .length() < QApplication::startDragDistance()) {
         return;
     }

     QDrag *drag = new QDrag(event->widget());
     QMimeData *mime = new QMimeData;
     drag->setMimeData(mime);

     static int n = 0;
     if (n++ > 2 && (qrand() % 3) == 0) {
         QImage image(":/images/head.png");
         mime->setImageData(image);

         drag->setPixmap(QPixmap::fromImage(image).scaled(30, 40));
         drag->setHotSpot(QPoint(15, 30));
     } else {
         mime->setColorData(color);
         mime->setText(QString("#%1%2%3")
                       .arg(color.red(), 2, 16, QLatin1Char('0'))
                       .arg(color.green(), 2, 16, QLatin1Char('0'))
                       .arg(color.blue(), 2, 16, QLatin1Char('0')));

         QPixmap pixmap(34, 34);
         pixmap.fill(Qt::white);

         QPainter painter(&pixmap);
         painter.translate(15, 15);
         painter.setRenderHint(QPainter::Antialiasing);
         paint(&painter, 0, 0);
         painter.end();

         pixmap.setMask(pixmap.createHeuristicMask());

         drag->setPixmap(pixmap);
         drag->setHotSpot(QPoint(15, 20));
     }

     drag->exec();
     setCursor(Qt::OpenHandCursor);
 }
开发者ID:mike-perdide,项目名称:gitbuster,代码行数:43,代码来源:coloritem.cpp

示例11: onBtnCameraDragAndDropPressed

void MainWindow::onBtnCameraDragAndDropPressed() {
    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;

    drag->setMimeData(mimeData);
    drag->setPixmap(QPixmap(":/assets/images/camera.png", 0, Qt::AutoColor));

    drag->setHotSpot(QPoint(5, 15));
    drag->exec(Qt::CopyAction);
}
开发者ID:jaybird19,项目名称:FRTMProDesign,代码行数:10,代码来源:mainwindow.cpp

示例12: mousePressEvent

//! [2]
void MyWidget::mousePressEvent(QMouseEvent *event)
{
//! [2]
    QString text = dataLabel->text();
    QPixmap iconPixmap(32, 32);
    iconPixmap.fill(qRgba(255, 0, 0, 127));
    QImage image(100, 100, QImage::Format_RGB32);
    image.fill(qRgb(0, 0, 255));

//! [3]
    if (event->button() == Qt::LeftButton) {

        QDrag *drag = new QDrag(this);
        QMimeData *mimeData = new QMimeData;

        mimeData->setText(text);
        mimeData->setImageData(image);
        drag->setMimeData(mimeData);
        drag->setPixmap(iconPixmap);

        Qt::DropAction dropAction = drag->exec();
//! [3]
        // ...
//! [4]
        event->accept();
    }
//! [4]
    else if (event->button() == Qt::MidButton) {

        QDrag *drag = new QDrag(this);
        QMimeData *mimeData = new QMimeData;

        mimeData->setImageData(image);
        drag->setMimeData(mimeData);
        drag->setPixmap(iconPixmap);

        Qt::DropAction dropAction = drag->exec();
        // ...
        event->accept();
    }
//! [5]
}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:43,代码来源:window.cpp

示例13: videoMouseMove

void VSCVWidget::videoMouseMove(QMouseEvent *e)
{
    VDC_DEBUG( "%s mouseMoveEvent %d\n",__FUNCTION__, m_nId);
    //if (e->pos().y() > height() - ui.videoControl->height()) {
        if (1) {
            //ui.videoControl->show();
            emit ShowFocusClicked(m_nId);
	     m_lastMoveTime = time(NULL);
        }
    if (m_pStarted == TRUE || m_InstantPbMode == TRUE)
    {
        if (m_DragStart == TRUE)
        {
           VDC_DEBUG( "%s mouseMoveEvent %d event x %d\n",__FUNCTION__, m_nId, e->x());
           if (abs(e->x() - m_lastDragX) < 5)
           {
               return;
           }
        }else if (m_PtzStart == TRUE)
        {
		if (abs(e->x() - m_lastPtzX) < 10 || abs(e->y() - m_lastPtzY) < 10 )
		{
		   return;
		}
		gFactory->DrawPtzDirection(m_nPlayId, m_videoWindow, 
			width()/2, height()/2, e->x(), e->y());
		PtzAction(width()/2, height()/2, e->x(), e->y());
		m_lastPtzX = e->x();
		m_lastPtzY = e->y();
		return;
        }
        else
        {
            return;
        }
        u32 nId = m_nId;
        m_DragStart = FALSE;
        VDC_DEBUG( "%s id %d\n",__FUNCTION__, nId);
    	QMimeData *mimeData = new QMimeData();
    	mimeData->setText(QString::number(nId + VWIDGET_ID_OFFSET));
    	
    	// Create drag
    	QPixmap pixmap(":/device/resources/camera1.png");
    	QPainter painter(&pixmap);
    
    	QDrag *drag = new QDrag(this);
    	drag->setMimeData(mimeData);
    	drag->setPixmap(pixmap);
                  drag->setHotSpot(QPoint(drag->pixmap().width()/2,
                         drag->pixmap().height()/2));
    	drag->exec();
        
    }
}
开发者ID:flashtree,项目名称:vdc,代码行数:54,代码来源:vscvwidget.cpp

示例14: activatedDragAndDrop

void StackFolder::activatedDragAndDrop(const KFileItem &item)
{

    QMimeData *mime = new QMimeData;
    QList<QUrl> urls;
    urls.append(item.url());
    mime->setUrls(urls);
    QDrag *drag = new QDrag(view());
    drag->setMimeData(mime);
    QString local_path = item.localPath();
    PreviewGenerator *gen = PreviewGenerator::createInstance();
    Q_ASSERT(gen != 0);

    if (gen->hasPreviewPixmap(local_path)) {
        drag->setPixmap(gen->getPreviewPixmap(item.localPath()).scaled(KIconLoader::SizeMedium, KIconLoader::SizeMedium, Qt::KeepAspectRatio));
    }
    else
        drag->setPixmap(item.pixmap(0));
    drag->exec(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction, Qt::CopyAction);
}
开发者ID:KDE,项目名称:stackfolder,代码行数:20,代码来源:stackfolder.cpp

示例15: startDrag

/**
 * QT 4.7.1 拖拽的函数默认调用过程:
 *
 * Model.supportedDropActions()
 *
 * View.startDrag()
 *     Model.mimeData() // 获取拖拽数据
 *     Model.supportedDragActions()
 *         Model.supportedDropActions()
 *     QDrag.exec() // 阻塞,直到拖拽结束
 *
 *         // 在拖拽过程中,如果拖拽进入某个节点
 *         View.dragEnterEvent() // 默认实现会拒绝拖拽,需要重写并调用 QDragEnterEvent.acceptProposedAction()
 *             Model.mimeTypes()
 *         View.dragMoveEvent()
 *             Model.mimeTypes()
 *         View.dragLeaveEvent()
 *
 *         // 拖拽结束后
 *         View.dropEvent()
 *             Model.dropMimeData() // QT用来接收数据
 *
 *     // exec()执行完后,如果是 MoveAction,则调用
 *     Model.removeSelectedRows() // QT用来删除数据
 *
 * 上述默认过程对跨 View 拖放支持不好, 下面的startDrag()函数摘自默认实现,并
 * 将部分代码替换掉以免调用removeSelectedRows()函数
 */
void DirectoryTree::startDrag(Qt::DropActions)
{
    const QModelIndexList indexes = selectedIndexes();
    if (indexes.count() == 0)
        return;

    // setup pixmap
    QRect rect = visualRect(indexes.at(0));
    QList<QRect> rects;
    for (size_t i = 0, s = indexes.count(); i < s; ++i)
    {
        rects.append(visualRect(indexes.at(i)));
        rect |= rects.at(i);
    }
    rect = rect.intersected(viewport()->rect());
    QPixmap pixmap(rect.size());
    pixmap.fill(palette().base().color());
    QPainter painter(&pixmap);
    QStyleOptionViewItem option = viewOptions();
    option.state |= QStyle::State_Selected;
    for (size_t j = 0, s = indexes.count(); j < s; ++j)
    {
        option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(),
        rects.at(j).size());
        itemDelegate()->paint(&painter, option, indexes.at(j));
    }
    painter.end();

    // create drag object
    QDrag *drag = new QDrag(this);
    drag->setPixmap(pixmap);
    drag->setMimeData(model()->mimeData(indexes));
    drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft());

    /**
     * 在拖动之前,先把 parent 和  row 保存下来,
     * 在 Model.dropMimeData() 中统一进行底层数据和视图层数据的修改,
     * 避免索引混乱
     */
    DirectoryTreeModel *m = (DirectoryTreeModel*) model();
    QModelIndex parent = indexes.at(0).parent();
    int row = indexes.at(0).row();
    m->prepare_draging_drop(parent, row);

    /*
     * 这里的原来的实现 removeSelectedRows() 是我们不需要的, 且 QDrag->start() 总是允许 Qt::CopyAction
     * 而我们需要的是,内部用 Qt::MoveAction,外部用 Qt::CopyAction且内部不支持 Qt::CopyAction且内部不支持
     * Qt::CopyAction,否则导致错误
     *
    if (drag->start(supportedActions) == Qt::MoveAction)
        removeSelectedRows();
    */
    drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);
}
开发者ID:jingqi,项目名称:organic,代码行数:82,代码来源:directory_tree.cpp


注:本文中的QDrag::setPixmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。