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


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

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


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

示例1: 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);
}
开发者ID:Atalanttore,项目名称:lxqt-panel,代码行数:35,代码来源:lxqttaskbutton.cpp

示例2: mouseMoveEvent

//! [5]
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);
//! [5]

//! [6]
    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));
//! [6]
//! [7]
    } 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));
    }
//! [7]

//! [8]
    drag->exec();
    setCursor(Qt::OpenHandCursor);
}
开发者ID:AtlantisCD9,项目名称:Qt,代码行数:50,代码来源:coloritem.cpp

示例3: startDrag

void Scene::startDrag(QPointF start)
{
    QGraphicsPixmapItem *item =
            dynamic_cast<QGraphicsPixmapItem *> (itemAt(start, QTransform()));

    QByteArray buffer;
    QDataStream stream(&buffer, QIODevice::WriteOnly);
    stream << item->pixmap(); // Сохраняем картинку в буфер

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

    data->setData("Picture", buffer);
    drag->setMimeData(data);
    drag->setPixmap(item->pixmap());

    relativePoint = item->mapFromScene(start);

    qDebug() << "Position at image:" << relativePoint;
    drag->setHotSpot(QPoint(relativePoint.x(), relativePoint.y()));

    removeItem(item); // удалить картинку
    internalMoving = true;

    update();

    drag->exec(Qt::MoveAction); // Начать выполнение Drag & Drop
}
开发者ID:medegor44,项目名称:Backpack,代码行数:28,代码来源:scene.cpp

示例4: 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);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:26,代码来源:qtresourceview.cpp

示例5: 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);
	}
}
开发者ID:335,项目名称:synergy,代码行数:30,代码来源:ScreenSetupView.cpp

示例6: 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);
}
开发者ID:weijer,项目名称:shotcut,代码行数:27,代码来源:glwidget.cpp

示例7: mousePressEvent

void PlayerCardListWidget::mousePressEvent(QMouseEvent *event)
{
    PlayerCardWidget *child = static_cast<PlayerCardWidget*>(childAt(event->pos()));
    if (!child)
        return;
    // Float up the hierachy until the PlayerCardWidget is found, or we hit the current widget
    while ((!child->property("PlayerCardWidget").isValid()) && ((PlayerCardListWidget*)child != this)) {
        child = static_cast<PlayerCardWidget*>(child->parent());
    }
    // If the child is not a PlayerCardWidget, return
    if (!child->property("PlayerCardWidget").isValid())
        return;
    QPoint hotSpot = event->pos() - child->pos();
    QByteArray itemData;
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    dataStream << child->playerNumber() << QPoint(hotSpot);

    QMimeData *mimeData = new QMimeData;
    mimeData->setData("application/x-chessplayer", itemData);
    mimeData->setText(child->player()->name());

    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->setPixmap(QPixmap::grabWidget(child));
    drag->setHotSpot(hotSpot);

    child->hide();

    if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction)
        child->close();
    else
        child->show();
}
开发者ID:mariusroets,项目名称:pairing,代码行数:33,代码来源:playercardlistwidget.cpp

示例8: mousePressEvent

void MainWindow::mousePressEvent(QMouseEvent *event)
{
    //1,获取图片
    QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
    if(!child->inherits("QLabel")) return;
    QPixmap pixmap = *child->pixmap();
    //2,自定义MIME类型
    QByteArray itemData;
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    dataStream<<pixmap<<QPoint(event->pos()-child->pos());
    //3,将数据放入QMimeData中
    QMimeData *mimeData = new QMimeData;
    mimeData->setData("image/png", itemData);
    //4,将数据放到QDrag中
    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->setPixmap(pixmap);
    drag->setHotSpot(event->pos()-child->pos());
    //5,原图添加阴影
    QPixmap tempPixmap = pixmap;
    QPainter painter;
    painter.begin(&tempPixmap);
    painter.fillRect(pixmap.rect(),QColor(127,127,127,127));
    painter.end();
    child->setPixmap(tempPixmap);
    //6,执行拖放操作
    if(drag->exec(Qt::CopyAction|Qt::MoveAction, Qt::CopyAction)
        ==Qt::MoveAction)
        child->close();
    else{
        child->show();
        child->setPixmap(pixmap);
    }
}
开发者ID:enbool,项目名称:test4,代码行数:34,代码来源:mainwindow.cpp

示例9: mousePressEvent

void ListItem::mousePressEvent(QMouseEvent *event)
{

    QPixmap pixmap(this->size());
    this->render(&pixmap);

    QByteArray itemData;
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    dataStream << (qint64)this;

    QMimeData *mimeData = new QMimeData;
    mimeData->setData(draggableType, itemData);

    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->setPixmap(pixmap);
    drag->setHotSpot(event->pos());

    QPixmap tempPixmap = pixmap;
    QPainter painter;
    painter.begin(&tempPixmap);
    painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127));
    painter.end();


    if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
        this->close();
    } else {
        this->show();
    }
}
开发者ID:jotek,项目名称:noteclick,代码行数:31,代码来源:listitem.cpp

示例10: startDrag

void PredefinedElementView::startDrag(Qt::DropActions supportedActions)
{
	// get the item at this position
	QMimeData * mimeData = model()->mimeData(selectedIndexes());
	if(mimeData == 0)
		return;

	// this should contains an element
	Element * element = mimeDataToElement(mimeData);
	if(element == 0)
		return QListView::startDrag(supportedActions);

	// create the pixmap
	ElementGraphicsItem * item = ElementFactory::Instance()->createGraphicsItem(element);
	QPoint hotSpot;
	QPixmap p = elementToPixmap(item, &hotSpot);
	delete item;

	// start the drag
	QDrag * d = new QDrag(this);
	d->setMimeData(mimeData);
	d->setPixmap(p);
	d->setHotSpot(QPoint(p.size().width()/2, p.size().height()/2));

	d->exec(supportedActions);
}
开发者ID:Dtai,项目名称:PokerbotClient,代码行数:26,代码来源:predefinedelementview.cpp

示例11: mousePressEvent

/**
 * @brief Slot triggers drag-and-drop.
 * The user start draging the pattern he wants to add to the timeline.
 * @param[in] mouse pressed event.
 */
void BARPatternBarScrollAreaContents::mousePressEvent(QMouseEvent *event)
{
    int x=event->pos().x(); /**< retrieves the position of the cursor. */

    BARPatternBar *pBar = static_cast<BARPatternBar*>(childAt(event->pos())); /**< childAt returns a pointer to the child that was clicked. This pointer, of type "widget", is then converted into a BARPatternBar type. */
    if (!pBar){return;} /**< checks that the object created isn't empty (NULL). */

    QSize patternSize(100,60); /**< the following lines created a pixmap that will be displayed on the cursor during drag-and-drop. */
    QPixmap pixmap(patternSize);
    pixmap.fill(pBar->getBgColor());

    QByteArray itemData; /**< the following lines pack up the data to be sent through the drag-and-drop. */
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    dataStream << pBar->getBgColor(); /**< stores the color of the bar being dragged. */
    dataStream << pBar->getPatternLength(); /**< stores the duration of the pattern associated to the bar being dragged. */

    QMimeData *mimeData = new QMimeData;
    mimeData->setData("application/x-dnditemdata", itemData); /**< store the data we prepared into the QMimeFile. */
    mimeData->setText(childAt(event->pos())->accessibleName()); /**< store the name of the pattern associated to the bar being dragged. */

    QDrag *drag = new QDrag(this); /**< crates the QDrag object. */
    drag->setMimeData(mimeData); /**< stores the data we packed up into the drag object. */
    drag->setPixmap(pixmap); /**< sets the image to be displayed on the cursor during the drag-and-drop. */

    drag->setHotSpot(event->pos() - pBar->pos()); /**< actually displays the pixmap on the cursor during drag-and-drop. */

    if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction){pBar->close();} /**< lines found on the Internet... */
    else {pBar->show();}
}
开发者ID:BdxMimo,项目名称:project-bar,代码行数:34,代码来源:barpatternbarscrollareacontents.cpp

示例12: mouseMoveEvent

void LayerEditScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if(!event->buttons() & Qt::LeftButton) {
        return;
    }

    if((event->scenePos() - _dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
        return;
    }

    qDebug() << "LayerEditScene::mouseMoveEvent - Starting a drag";

    // Get the pixmap item related to the start of the drag.
    QGraphicsItem *item = itemAt(_dragStartPosition, QTransform());
    if(item == 0) {
        // Couldn't find an item at the location for some reason.
        qDebug() << "LayerEditScene::mouseMoveEvent - Could not find a sprite at the drag location.";
        return;
    }

    // Static cast is safe because this scene only adds QGraphicsPixmapItem
    QGraphicsPixmapItem *pixmapItem = static_cast<QGraphicsPixmapItem *>(item);

    // Remove item from scene
    Sprite sprite = _pixmapToSprite[pixmapItem]; // Save sprite before it's removed.
    qDebug() << "LayerEditScene::mouseMoveEvent - Dragging " << sprite.getFileInfo().fileName();

    int index = _previews.indexOf(pixmapItem);
    if(index != -1) {
        removeSprite(index);
        recalculatePositions();
    }

    // Create a new drag event and put the source image into the mime data.
    QDrag *drag = new QDrag((QObject *)event->widget());
    QMimeData *data = new QMimeData();
    data->setImageData(sprite.getTexture());
    data->setText(sprite.getFileInfo().absoluteFilePath());
    drag->setMimeData(data);

    // Put the pixmap that was selected onto the cursor
    QPixmap pixmap = pixmapItem->pixmap();
    drag->setPixmap(pixmap);
    drag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2));

    // Execute the drag with a move action.
    qDebug() << "LayerEditScene::mouseMoveEvent - Executing drag as MoveAction";
    Qt::DropAction action = drag->exec(Qt::MoveAction, Qt::MoveAction);

    if(action != Qt::MoveAction) {
        // Put sprite back
        qDebug() << "LayerEditScene::mouseMoveEvent - Move action failed, putting sprite back where it was.";
        insertSprite(index, sprite);
        recalculatePositions();
    } else {
        // Delete the old item
        qDebug() << "LayerEditScene::mouseMoveEvent - Move succeeded, deleting old sprite.";
        delete pixmapItem;
    }
}
开发者ID:cdettmering,项目名称:fancyland-editor,代码行数:60,代码来源:LayerEditScene.cpp

示例13: mousePressEvent

void DragDropArea::mousePressEvent(QMouseEvent *event)
{
    QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
    if (!child)
        return;

    // Only drag children with dynamic property: "drag"
    if (!child->property("drag").toBool())
        return;

    QPoint hotSpot = event->pos() - child->pos();

    QMimeData *mimeData = new QMimeData;
    mimeData->setText(child->text());
    mimeData->setData("application/x-hotspot",
                      QByteArray::number(hotSpot.x())
                      + " " + QByteArray::number(hotSpot.y()));

    QPixmap pixmap(child->size());
    child->render(&pixmap);

    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->setPixmap(pixmap);
    drag->setHotSpot(hotSpot);
    drag->exec();
}
开发者ID:arielmr,项目名称:SofiaTrigo,代码行数:27,代码来源:dragdroparea.cpp

示例14: createAndDrag

void AssemblyCreateAndDrag::createAndDrag()
{

    QByteArray itemData(sizeof(QScriptValue*),0);

    QScriptValue * copy = new QScriptValue( scriptValue.engine()->newObject() );

    QScriptValueIterator iter(scriptValue);
    while( iter.hasNext() )
    {
        iter.next();
        copy->setProperty( iter.name() , iter.value() );
    }

    memcpy( itemData.data() , &copy , sizeof(QScriptValue*) );
    QMimeData * mimeData = new QMimeData;
    mimeData->setData( type , itemData );

    this->setDown(false);

    QDrag * drag = new QDrag(this);
    drag->setMimeData( mimeData );
    drag->setPixmap( icon );
    drag->setHotSpot( QPoint( drag->pixmap().width()/2 , drag->pixmap().height()/2 ) );
    drag->exec();
}
开发者ID:igemsoftware,项目名称:USTC-Software_2011,代码行数:26,代码来源:AssemblyCreateAndDrag.cpp

示例15: hotspot

    virtual Q3DragObject *dragObject ()
    {
      int count = 0;
      for ( Q3IconViewItem *it = firstItem(); it; it = it->nextItem() ) {
        if ( it->isSelected() ) {
          ++count;
        }
      }

      QPixmap pixmap;
      if ( count > 1 ) {
        pixmap = KIconLoader::global()->loadIcon( "mail-attachment", KIconLoader::Desktop );
      }
      if ( pixmap.isNull() ) {
        pixmap = static_cast<AttachmentIconItem *>( currentItem() )->icon();
      }

      QPoint hotspot( pixmap.width() / 2, pixmap.height() / 2 );

      QDrag *drag = new QDrag( this );
      drag->setMimeData( mimeData() );

      drag->setPixmap( pixmap );
      drag->setHotSpot( hotspot );
      drag->exec( Qt::CopyAction );
      return 0;
    }
开发者ID:akhuettel,项目名称:kdepim-noakonadi,代码行数:27,代码来源:koeditorattachments.cpp


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