本文整理汇总了C++中QMouseEvent::globalPos方法的典型用法代码示例。如果您正苦于以下问题:C++ QMouseEvent::globalPos方法的具体用法?C++ QMouseEvent::globalPos怎么用?C++ QMouseEvent::globalPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMouseEvent
的用法示例。
在下文中一共展示了QMouseEvent::globalPos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool HScrollArea::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseMove) {
QMouseEvent* me = (QMouseEvent*) event;
if ((me->buttons() & Qt::LeftButton)) {
if (!mMoveStart) {
mMoveStart = true;
mContinousMove =false;
mMousePoint = me->globalPos();
}
else {
scrollBar = horizontalScrollBar();
QPoint p = me->globalPos();
int offset = p.x() - mMousePoint.x();
if( !mContinousMove && ( offset > -10 && offset < 10 ) )
return false;
mContinousMove = true;
scrollBar->setValue(scrollBar->value() - offset);
mMousePoint = p;
}
return true;
}
}
else if (event->type() == QEvent::MouseButtonRelease) {
mMoveStart = false;
}
return QObject::eventFilter(obj, event);
}
示例2: eventFilter
bool AppInit::eventFilter(QObject *obj, QEvent *evt)
{
QWidget *w = (QWidget *)obj;
if (!w->property("CanMove").toBool()) {
return QObject::eventFilter(obj, evt);
}
QMouseEvent *event = static_cast<QMouseEvent *>(evt);
if (event->type() == QEvent::MouseButtonPress) {
if (event->button() == Qt::LeftButton) {
mousePressed = true;
mousePoint = event->globalPos() - w->pos();
return true;
}
} else if (event->type() == QEvent::MouseButtonRelease) {
mousePressed = false;
return true;
} else if (event->type() == QEvent::MouseMove) {
if (mousePressed && (event->buttons() && Qt::LeftButton)) {
w->move(event->globalPos() - mousePoint);
return true;
}
}
return QObject::eventFilter(obj, evt);
}
示例3: recognize
QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
if (event->type() == QEvent::TouchBegin) {
// ignore the following mousepress event
g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(true));
} else if (event->type() == QEvent::TouchEnd) {
g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false));
}
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (event->type() == QEvent::MouseButtonPress) {
if (g->property("ignoreMousePress").toBool())
return QGestureRecognizer::Ignore;
g->setHotSpot(me->globalPos());
g->setProperty("startPos", me->globalPos());
g->setProperty("pressed", QVariant::fromValue<bool>(true));
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove) {
if (g->property("pressed").toBool()) {
QPoint offset = me->globalPos() - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
g->setOffset(QPointF(offset.x(), offset.y()));
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease) {
if (g->property("pressed").toBool())
return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
示例4: eventFilter
bool FileViewFloatItem::eventFilter(QObject *object, QEvent *e)
{
if ( !enabled() || !visible() ) {
return false;
}
MarbleWidget *widget = dynamic_cast<MarbleWidget*> (object);
if ( !widget ) {
return AbstractFloatItem::eventFilter(object, e);
}
if ( m_marbleWidget != widget ) {
// Delayed initialization
m_marbleWidget = widget;
}
Q_ASSERT( m_marbleWidget );
// Mouse events are forwarded to the underlying widget
QMouseEvent *event = static_cast<QMouseEvent*> (e);
QRectF floatItemRect = QRectF( positivePosition(), size() );
QPoint shiftedPos = event->pos() - floatItemRect.topLeft().toPoint()
- QPoint( padding(), padding() );
if( e->type() == QEvent::MouseMove ) {
m_itemPosition = event->globalPos();
}
if( floatItemRect.contains( event->pos() ) ) {
QWidget *child = m_fileViewParent->childAt( shiftedPos );
if( child ) {
m_marbleWidget->setCursor( Qt::ArrowCursor );
// there needs to be some extra handling for the scrollbars
// these need some special treatment due to them not forwarding
// their mouseevents to their scrollbars.
if( reinterpret_cast<QScrollBar*>( child ) == m_fileView->horizontalScrollBar() ) {
shiftedPos -= QPoint( 0, m_fileView->viewport()->size().height() );
} else if( reinterpret_cast<QScrollBar*>( child ) == m_fileView->verticalScrollBar() ) {
shiftedPos -= QPoint( m_fileView->viewport()->size().width(), 0 );
}
QMouseEvent shiftedEvent( e->type(), shiftedPos,
event->globalPos(), event->button(), event->buttons(),
event->modifiers() );
if( QApplication::sendEvent(child, &shiftedEvent) ) {
if( e->type() == QEvent::MouseButtonPress ||
e->type() == QEvent::MouseButtonRelease ||
e->type() == QEvent::MouseButtonDblClick ||
e->type() == QEvent::MouseMove )
updateFileView();
return true;
}
}
}
return AbstractFloatItem::eventFilter(object, e);
}
示例5: eventFilter
bool FramelessMove::eventFilter(QObject *obj, QEvent *ev)
{
if (obj == _monitor)
{
switch(ev->type())
{
case QEvent::MouseButtonPress:
{
QMouseEvent* event = (QMouseEvent*)ev;
if(event->button() == Qt::LeftButton)
{
_offsetPos = event->globalPos();
emit Pressed(_offsetPos);
lButtonPress = true;
}
break;
}
case QEvent::MouseButtonRelease:
{
QMouseEvent* event = (QMouseEvent*)ev;
if(event->button() == Qt::LeftButton && lButtonPress)
{
lButtonPress = false;
emit Release(event->globalPos());
}
break;
}
case QEvent::MouseMove:
{
if(lButtonPress)
{
QMouseEvent* event = (QMouseEvent*)ev;
QPoint newPos = event->globalPos() - _offsetPos;
emit Offset(newPos);
if(_target)
_target->move(_target->pos() + newPos);
_offsetPos = event->globalPos();
}
break;
}
default:
break;
}
}
return false;
}
示例6: mouseMoveEvent
void CPrivateInfo::mouseMoveEvent(QMouseEvent *ev)
{
QMouseEvent *mv = (QMouseEvent*) ev;
QRect labelrect = QRect(ui->lb_top->pos() + this->pos(), ui->lb_top->size());
if(labelrect.contains(mv->globalPos()))
{
this->move(mv->globalX() - m_Ptcur.rx(), mv->globalY() - m_Ptcur.ry());
m_Ptbefore = mv->globalPos();
sleep(0.1);
}
}
示例7: eventFilter
bool CloudView::eventFilter(QObject *obj, QEvent *event)
{
if (obj == mHeader) {
static QPoint oldPos;
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *ev = (QMouseEvent *)event;
oldPos = ev->globalPos();
return true;
} else if (event->type() == QEvent::MouseMove) {
QMouseEvent *ev = (QMouseEvent *)event;
const QPoint delta = ev->globalPos() - oldPos;
MainWindow *win = seafApplet->mainWindow();
win->move(win->x() + delta.x(), win->y() + delta.y());
oldPos = ev->globalPos();
return true;
}
} else if (obj == mDropArea) {
if (event->type() == QEvent::DragEnter) {
QDragEnterEvent *ev = (QDragEnterEvent *)event;
if (ev->mimeData()->hasUrls() && ev->mimeData()->urls().size() == 1) {
const QUrl url = ev->mimeData()->urls().at(0);
if (url.scheme() == "file") {
QString path = url.toLocalFile();
#if defined(Q_OS_MAC) && (QT_VERSION <= QT_VERSION_CHECK(5, 4, 0))
path = utils::mac::fix_file_id_url(path);
#endif
if (QFileInfo(path).isDir()) {
ev->acceptProposedAction();
}
}
}
return true;
} else if (event->type() == QEvent::Drop) {
QDropEvent *ev = (QDropEvent *)event;
const QUrl url = ev->mimeData()->urls().at(0);
QString path = url.toLocalFile();
#if defined(Q_OS_MAC) && (QT_VERSION <= QT_VERSION_CHECK(5, 4, 0))
path = utils::mac::fix_file_id_url(path);
#endif
ev->setDropAction(Qt::CopyAction);
ev->accept();
showCreateRepoDialog(path);
return true;
}
}
return QWidget::eventFilter(obj, event);
}
示例8: eventFilter
bool KDockSplitter::eventFilter(QObject *o, QEvent *e)
{
QMouseEvent *mev;
bool handled = false;
int factor = (mHighResolution)? 10000:100;
switch (e->type()) {
case QEvent::MouseMove:
mev= (QMouseEvent*)e;
child0->setUpdatesEnabled(mOpaqueResize);
child1->setUpdatesEnabled(mOpaqueResize);
if (orientation == Horizontal) {
if (!mOpaqueResize) {
int position = checkValue( mapFromGlobal(mev->globalPos()).y() );
divider->move( 0, position );
} else {
xpos = factor * checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
resizeEvent(0);
divider->repaint(true);
}
} else {
if (!mOpaqueResize) {
int position = checkValue( mapFromGlobal(QCursor::pos()).x() );
divider->move( position, 0 );
} else {
xpos = factor * checkValue( mapFromGlobal( mev->globalPos()).x() ) / width();
resizeEvent(0);
divider->repaint(true);
}
}
handled= true;
break;
case QEvent::MouseButtonRelease:
child0->setUpdatesEnabled(true);
child1->setUpdatesEnabled(true);
mev= (QMouseEvent*)e;
if (orientation == Horizontal){
xpos = factor* checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
resizeEvent(0);
divider->repaint(true);
} else {
xpos = factor* checkValue( mapFromGlobal(mev->globalPos()).x() ) / width();
resizeEvent(0);
divider->repaint(true);
}
handled= true;
break;
default:
break;
}
return (handled) ? true : QWidget::eventFilter( o, e );
}
示例9: mousePressEvent
void CPrivateInfo::mousePressEvent(QMouseEvent * ev)
{
QMouseEvent *mv = (QMouseEvent*) ev;
if(mv->buttons() & Qt::LeftButton)
{
QRect labelrect = QRect(ui->lb_top->pos() + this->pos(), ui->lb_top->size());
if(labelrect.contains(mv->globalPos()))
{
m_Ptbefore = mv->globalPos();
m_Ptcur = mv->pos();
}
}
}
示例10: eventFilter
bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
{
if(!currentImageSteps->at(*currentStep))
return false;
if(obj == currentImageLabel && ev->type() == QEvent::MouseMove)
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(ev);
QPoint pnt = currentImageLabel->mapFromGlobal(mouseEvent->globalPos());
QColor currentPixel = currentImageSteps->at(*currentStep)->pixel(pnt);
statusBar()->showMessage(QString("%[email protected](%2,%3)").arg(currentPixel.lightness()&0xFF).arg(pnt.x()).arg(pnt.y()));
currentRubberBand->setGeometry(QRect(rbOrigin,pnt).normalized());
return true;
}
if(obj == currentImageLabel && ev->type() == QEvent::MouseButtonPress)
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(ev);
rbOrigin = currentImageLabel->mapFromGlobal(mouseEvent->globalPos());
currentRubberBand->setGeometry(QRect(rbOrigin,QSize()));
currentRubberBand->show();
}
if(obj == currentImageLabel && ev->type() == QEvent::MouseButtonRelease)
{
currentRubberBand->hide();
*currentImageSteps << new QImage(currentImageSteps->at(*currentStep)->copy(currentRubberBand->geometry()));
*currentStep = currentImageSteps->size()-2;
nextImage();
/*
SparseMatrix* sm = buildModel(img);
QDialog* dlg = new QDialog(this);
QHBoxLayout* mainLayout = new QHBoxLayout(dlg);
QTextEdit *edit = new QTextEdit(this);
edit->setReadOnly(true);
edit->setText(sm->toString());
edit->resize(800,600);
mainLayout->addWidget(edit);
dlg->setLayout(mainLayout);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->resize(800,600);
dlg->show();
delete sm;
*/
}
return false;
}
示例11: eventFilter
bool RKConsole::eventFilter (QObject *, QEvent *e) {
if (e->type () == QEvent::KeyPress) {
QKeyEvent *k = (QKeyEvent *)e;
return handleKeyPress (k);
} else if (e->type () == QEvent::MouseButtonPress){
QMouseEvent *m = (QMouseEvent *)e;
if (m->button() == Qt::RightButton) {
doPopupMenu (m->globalPos ());
return (true);
}
return (false);
} else if (e->type () == QEvent::MouseButtonRelease){
QMouseEvent *m = (QMouseEvent *)e;
if (m->button() == Qt::MidButton) {
QClipboard *cb = QApplication::clipboard ();
submitBatch (cb->text (QClipboard::Selection));
return (true);
} /* else if (m->button () == Qt::LeftButton) {
// prevent cursor from leaving last line
uint para=0; uint p=0;
view->cursorPosition (¶, &p);
if (para != doc->numLines () - 1) {
int y = view->y ();
view->setCursorPosition (doc->numLines() -1, p);
int y2 = view->y ();
qDebug ("%d, %d", y, y2);
view->scroll (0, y - y2);
}
} */ // not good, yet: always jumps to bottom of view
return (false);
} else {
return false;
}
}
示例12: eventFilter
//
// eventFilter - filter events looking for a rightclick
//
// On a right mouseclick we call the addButton method since I can't get
// the popup menu working
//
bool
MsgDialog::eventFilter(QObject *o, QEvent *e)
{
switch (e->type())
{
case QEvent::MouseButtonPress:
{
QMouseEvent *m = (QMouseEvent *) e;
if (m->button() == 1) // left click
{
}
if (m->button() == 2) // right click
{
m_pMenu->popup(m->globalPos());
return TRUE; // don't process event any further
}
}
break;
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::MouseMove:
default:
break;
}
return QWidget::eventFilter(o, e);
} // end eventFilter
示例13: eventFilter
bool TCPopup::eventFilter(QObject *watched, QEvent *event)
{
/* if ( event->type() == QEvent::FocusIn && watched == ui.translateBox->translateLine() )
{
QFocusEvent * focusEvent = static_cast< QFocusEvent * >( event );
// select all on mouse click
if ( focusEvent->reason() == Qt::MouseFocusReason ) {
QTimer::singleShot(0, this, SLOT(focusTranslateLine()));
}
return false;
} */
if ( mouseIntercepted )
{
// We're only interested in our events
if ( event->type() == QEvent::MouseMove )
{
// DPRINTF( "Object: %s\n", watched->objectName().toUtf8().data() );
QMouseEvent * mouseEvent = ( QMouseEvent * ) event;
reactOnMouseMove( mouseEvent->globalPos() );
}
}
return QWidget::eventFilter( watched, event );
}
示例14: eventFilter
bool PersonalChatDlg::eventFilter(QObject *obj, QEvent *event)
{
if(obj == ui->btn_min){ //最小化、最大化、关闭按钮换图
if(event->type() == QEvent::Enter){
ui->btn_min->setPixmap(QPixmap(":/pixmap/image/miniButton-hover.png"));
}else if(event->type() == QEvent::Leave){
ui->btn_min->setPixmap(QPixmap(":/pixmap/image/miniButton.png"));
}else if(event->type() == QEvent::MouseButtonPress){
ui->btn_min->setPixmap(QPixmap(":/pixmap/image/miniButton-hover.png"));
}else if(event->type() == QEvent::MouseButtonRelease){
QMouseEvent *me = (QMouseEvent *)event;
QLabel *lb = (QLabel *)obj;
if(me->x() > 0 && me->x() < lb->width() && me->y() > 0 && me->y() < lb->height()){
this->showMinimized();
}else{
ui->btn_min->setPixmap(QPixmap(":/pixmap/image/miniButton.png"));
}
} else {
return QObject::eventFilter(obj, event);
}
}
if(obj == ui->btn_close){ //最小化、最大化、关闭按钮换图
if(event->type() == QEvent::Enter){
ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeButton-hover.png"));
}else if(event->type() == QEvent::Leave){
ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeButton.png"));
}else if(event->type() == QEvent::MouseButtonPress){
ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeButton-hover.png"));
}else if(event->type() == QEvent::MouseButtonRelease){
QMouseEvent *me = (QMouseEvent *)event;
QLabel *lb = (QLabel *)obj;
if(me->x() > 0 && me->x() < lb->width() && me->y() > 0 && me->y() < lb->height()){
this->close();
emit closePersonalchatdlg(bareJid);
}else{
ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeButton.png"));
}
} else {
return QObject::eventFilter(obj, event);
}
}
if(obj==ui->closeButton||obj==ui->sendMessageButton
||obj==ui->sendfileButton
||obj==ui->saveFileButton
||obj==ui->refuseButton)
{
if(event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *me = (QMouseEvent *)event;
dragPos = me->globalPos() - frameGeometry().topLeft();
}else if(event->type() == QEvent::MouseButtonRelease)
{
setWindowOpacity(1);
}
}
return QObject::eventFilter(obj, event);
}
示例15: eventFilter
bool DataViewer::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::RightButton)
{
const QPoint globalMousePos = mouseEvent->globalPos();
QTableView *tableView = d_ptr->m_tableData;
Q_ASSERT(tableView);
const QModelIndex tableModelIndex = tableView->indexAt(mouseEvent->pos());
if (tableModelIndex.isValid())
{
QVariant data = tableView->model()->data(tableModelIndex);
bool ok = false;
int timestamp = data.toInt(&ok);
if (ok)
{
QMenu menu;
menu.addAction(d_ptr->m_timestampAction);
if (menu.exec(globalMousePos))
{
QMessageBox::information(this, QString(), QDateTime::fromTime_t(timestamp).toString());
}
}
}
}
}
return BaseViewer::eventFilter(watched, event);
}