本文整理汇总了C++中QLabel::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ QLabel::pos方法的具体用法?C++ QLabel::pos怎么用?C++ QLabel::pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLabel
的用法示例。
在下文中一共展示了QLabel::pos方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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();
}
示例3: imagePosition
/*! \internal */
QRect QAccessibleDisplay::imagePosition() const
{
QLabel *label = qobject_cast<QLabel *>(widget());
if (!label)
return QRect();
const QPixmap *pixmap = label->pixmap();
if (!pixmap)
return QRect();
return QRect(label->mapToGlobal(label->pos()), label->size());
}
示例4: mousePressEvent
void MainWindow::mousePressEvent(QMouseEvent *event){
// imprimindo mensagem de debug
qDebug()<<"MainWindow::mousePressEvent(QMouseEvent *event)";
QLabel *label = static_cast<QLabel*>(childAt(event->pos()));
if (!label || label->objectName()=="centralWidget"
|| label->objectName()==""
|| label->objectName()=="diagrama"){
return;
}
// imprimindo mensagem para debug
qDebug()<<label->objectName();
QPixmap pixmap = *label->pixmap();
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << pixmap << QPoint(event->pos() - label->pos());
QMimeData *mimeData = new QMimeData();
mimeData->setData("application/x-dnditemdata", itemData);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
drag->setHotSpot(event->pos() - label->pos());
QPoint pointAtual = event->pos();
if(pointAtual.x() > ui->diagrama->geometry().x()
&& pointAtual.y() > ui->diagrama->geometry().y()
&& pointAtual.x() < ui->diagrama->width()) {
label->close();
}
if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
label->show();
label->setPixmap(pixmap);
}
}
示例5: QPropertyAnimation
void
TopBar::fadeOutDude( unsigned int i )
{
// qDebug() << Q_FUNC_INFO << i;
QLabel* dude = m_dudes.at( i );
QPropertyAnimation* ani = new QPropertyAnimation( dude, "pos" );
ani->setDuration( 1000 );
ani->setEasingCurve( QEasingCurve::OutQuad );
ani->setStartValue( dude->pos() );
ani->setEndValue( QPoint( -10, 0 ) );
qDebug() << "Animating from" << ani->startValue() << "to" << ani->endValue();
connect( ani, SIGNAL( finished() ), ani, SLOT( deleteLater() ) );
ani->start();
}
示例6: dataStream
//---------------------------------------------------------------------------
// dropEvent
//
//! The event handler that receives drop events.
//
//! @param event the drop event
//---------------------------------------------------------------------------
void
GraphicalRack::dropEvent (QDropEvent* event)
{
if (event->mimeData()->hasFormat (mime_type)) {
QByteArray itemData = event->mimeData()->data (mime_type);
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
QPixmap pixmap;
QPoint sourcePos;
QPoint offset;
dataStream >> pixmap >> sourcePos >> offset;
QLabel* droppedTile = new QLabel;
droppedTile->setPixmap(pixmap);
droppedTile->setAttribute (Qt::WA_DeleteOnClose);
QPoint dropPos = event->pos() - offset;
// Move the tile an extra half tile width in the direction of the
// move. This allows the tile to assume a new spot if it is dragged
// more than halfway onto the spot.
int extraMove = (sourcePos.x() < dropPos.x() ? 50 / 2
: -50 / 2);
dropPos.setX(dropPos.x() + extraMove);
for(int i = 0; i < m_layout->count(); ++i) {
QLabel *label = qobject_cast<QLabel*>(m_layout->itemAt(i)->widget());
if (!label) { // hit the stretcher
m_layout->insertWidget(i, droppedTile);
break;
}
if (dropPos.x() > label->pos().x()) {
continue;
}
m_layout->insertWidget(i, droppedTile);
break;
}
if (event->source() == this) {
event->setDropAction (Qt::MoveAction);
event->accept();
} else {
event->acceptProposedAction();
}
}
示例7: imagePosition
/*! \internal */
QRect QAccessibleDisplay::imagePosition(QAccessible2::CoordinateType coordType)
{
QLabel *label = qobject_cast<QLabel *>(widget());
if (!label)
return QRect();
const QPixmap *pixmap = label->pixmap();
if (!pixmap)
return QRect();
switch (coordType) {
case QAccessible2::RelativeToScreen:
return QRect(label->mapToGlobal(label->pos()), label->size());
case QAccessible2::RelativeToParent:
return label->geometry();
}
return QRect();
}