本文整理汇总了C++中QMouseEvent类的典型用法代码示例。如果您正苦于以下问题:C++ QMouseEvent类的具体用法?C++ QMouseEvent怎么用?C++ QMouseEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMouseEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
bool HelpBrowser::eventFilter(QObject *object, QEvent *event)
{
if (object == mWebView) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent * mouseEvent = static_cast<QMouseEvent*>(event);
switch (mouseEvent->button()) {
case Qt::XButton1:
mWebView->pageAction(QWebPage::Back)->trigger();
return true;
case Qt::XButton2:
mWebView->pageAction(QWebPage::Forward)->trigger();
return true;
default:
break;
}
break;
}
case QEvent::ShortcutOverride: {
QKeyEvent * kevent = static_cast<QKeyEvent*>(event);
if ( kevent == QKeySequence::Copy ||
kevent == QKeySequence::Paste )
{
kevent->accept();
return true;
}
break;
}
default:
break;
}
}
return false;
}
示例2: rectLeft
bool MoveDelegate::editorEvent(QEvent *event, QAbstractItemModel *, const QStyleOptionViewItem &option, const QModelIndex &index)
{
QRect rect = option.rect;
QRect rectLeft(rect.x() + rect.width()/4 - 8, rect.y() + rect.height()/2 - 5 , 30, 15);
QRect rectRight(rect.x() + rect.width()*3/4 -8, rect.y() + rect.height()/2 - 5 , 30, 15);
if (event->type() == QEvent::MouseMove) {
// QMouseEvent* e =(QMouseEvent*)event;
}
if (event->type() == QEvent::MouseButtonRelease) {
QMouseEvent* e =(QMouseEvent*)event;
int row = index.row();
if (rectLeft.contains(e->x(), e->y())) {
emit left(row);
return true;
}
else if(rectRight.contains(e->x(), e->y())){
emit right(row);
return true;
}
}
return false;
}
示例3: if
bool Nepomuk::AnnotationDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
{
if ( event->type() == QEvent::MouseButtonPress ) {
QMouseEvent* me = static_cast<QMouseEvent*>( event );
if ( me->button() == Qt::LeftButton ) {
if ( plusRect( option ).contains( me->pos() ) ) {
kDebug() << "Clicked plus";
Annotation* anno = index.data( AnnotationModel::AnnotationRole ).value<Nepomuk::Annotation*>();
anno->create( d->resource );
delete anno;
return true;
}
else if ( minusRect( option ).contains( me->pos() ) ) {
kDebug() << "Clicked minus";
Annotation* anno = index.data( AnnotationModel::AnnotationRole ).value<Nepomuk::Annotation*>();
anno->setUserRelevance( 0.0 );
delete anno;
return true;
}
}
}
return false;
}
示例4: mouseReleased
bool ComboBoxItemDelegate::mouseReleased(QEvent * event)
{
if (event->type() != QEvent::MouseButtonRelease)
return false;
QAbstractItemModel* model = mCombo->model();
QMouseEvent *ev = static_cast<QMouseEvent*>(event);
QModelIndex index = mCombo->view()->indexAt(ev->pos());
QVariant removable = index.data(ITEM_REMOVABLE_ROLE);
bool remove = true;
if (removable.type() == QVariant::Bool)
remove = removable.toBool();
if (remove && mLastIndex == index && model && index.data(Qt::UserRole).toString() != INVALID_DATA) {
QStyleOptionMenuItem opt = getStyleOption(mLastStyleOption, index);
int height = opt.rect.height();
if (ev->x() >= opt.rect.width()-height) {
emit removeItem(index.row());
return true;
}
}
return false;
}
示例5: switch
//=============================================================================
// eControl::paintEvent
//-----------------------------------------------------------------------------
bool eControl::event(QEvent* event)
{
switch(event->type())
{
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
{
QMouseEvent* me = (QMouseEvent*)event;
bool ok = event->type() == QEvent::MouseMove ? ((me->buttons() & Qt::LeftButton) != 0) : (me->button() == Qt::LeftButton);
if(ok)
{
float x = float(me->x())/width();
float y = float(me->y())/height();
OnTouch(x, y, event->type() != QEvent::MouseButtonRelease, 0);
return true;
}
}
return true;
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QTouchEvent* te = (QTouchEvent*)event;
foreach(const QTouchEvent::TouchPoint& p, te->touchPoints())
{
float x = p.pos().x()/width();
float y = p.pos().x()/height();
OnTouch(x, y, p.state() != Qt::TouchPointReleased, p.id());
}
}
return true;
default:
return QWidget::event(event);
}
}
示例6: switch
bool RSButtonOnText::isEventForThis(QObject *obj, QEvent *event, QPoint &point)
{
switch (event->type()) {
case QEvent::MouseButtonPress://2
case QEvent::MouseButtonRelease://3
case QEvent::MouseButtonDblClick://4
case QEvent::MouseMove://5
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
point = mouseEvent->pos();
}
break;
case QEvent::ToolTip://110
{
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
point = helpEvent->globalPos();
}
break;
default:
return false;
}
if (!event->isAccepted()) return false;//Already other take this event (true by default)
if (obj ==_textEditViewPort) {
if (_textEdit){
QTextCursor cursor = _textEdit->cursorForPosition(point);
if ( (_textCursor->anchor() <= cursor.anchor())
&& (cursor.position() <= _textCursor->anchor()+_lenght)){
return true;
}
}
}
return false;
}
示例7: resizeLabel
bool CustomerView::eventFilter(QObject* label, QEvent* vt)
{
if(label==m_ui->m_scrollAreaVisual)
{
/*if(vt->type() == QEvent::Resize)
{
resizeLabel();
}*/
}
else if((label == m_label)&&
((vt->type() == QEvent::MouseButtonPress)||(vt->type() == QEvent::MouseButtonRelease)||(vt->type() == QEvent::MouseMove)))
{
QMouseEvent* evt = static_cast<QMouseEvent*>(vt);
QPoint posOnLabel= evt->pos();
int w = m_label->geometry().width();
int h = m_label->geometry().height();
qreal ratioW = static_cast<qreal>(m_window->width())/ static_cast<qreal>(w);
qreal ratioH = static_cast<qreal>(m_window->height())/static_cast<qreal>(h);
qreal x = (posOnLabel.x()) * ratioW;
qreal y = (posOnLabel.y()) * ratioH;
QPointF posOnQML(x,y);
QMouseEvent* event = new QMouseEvent(evt->type(),posOnQML.toPoint(),evt->button(),evt->buttons(),evt->modifiers());
QObject* root = m_engine->rootObjects().first();
//QCoreApplication::sendEvent(m_window,event);
QCoreApplication::sendEvent(root,event);
//m_window->sendEvent(m_window->contentItem(),event);
return true;
}
return false;
}
示例8: slotMouseReleased
void QwtPlotWidget::slotMouseReleased( const QMouseEvent &e)
{
double x,y;
char buf[100];
int dx = 0;
int dy = 0;
QwtScaleWidget *awx = axisWidget(QwtPlot::yLeft);
if(awx != NULL) dx = awx->width();
QwtScaleWidget *awy = axisWidget(QwtPlot::xTop);
if(awy != NULL) dy = awy->height();
x = this->invTransform(QwtPlot::xBottom, e.pos().x() - dx);
y = this->invTransform(QwtPlot::yLeft, e.pos().y() - dy);
sprintf( buf, "QPlotMouseReleased(%d,%f,%f)\n",id, x, y );
tcp_send(s,buf,strlen(buf));
}
示例9: eventFilter
bool FancyTabProxyStyle::eventFilter(QObject* o, QEvent* e)
{
QTabBar* bar = qobject_cast<QTabBar*>(o);
if (bar && (e->type() == QEvent::MouseMove || e->type() == QEvent::Leave)) {
QMouseEvent* event = static_cast<QMouseEvent*>(e);
const QString old_hovered_tab = bar->property("tab_hover").toString();
const QString hovered_tab = e->type() == QEvent::Leave ? QString() : bar->tabText(bar->tabAt(event->pos()));
bar->setProperty("tab_hover", hovered_tab);
if (old_hovered_tab != hovered_tab) {
bar->update();
}
}
return false;
}
示例10: eventFilter
bool GooeyDoubleSpinBox::eventFilter(QObject* object, QEvent* event)
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
switch(event->type())
{
case QEvent::MouseButtonPress:
if(mouseEvent->button() == Qt::LeftButton)
{
_lastMousePos = mouseEvent->globalPos();
}
break;
case QEvent::MouseButtonRelease:
if(mouseEvent->button() == Qt::LeftButton)
{
_lastMousePos = QPoint(); // Reset the point !
}
break;
case QEvent::MouseMove:
if(mouseEvent->buttons() & Qt::LeftButton)
{
QPoint pos = mouseEvent->globalPos();
double dx = _spinBox->singleStep() * (pos.x() - _lastMousePos.x());
if(mouseEvent->modifiers() & Qt::CTRL)
{
dx *= 2.0;
}
else if(mouseEvent->modifiers() & Qt::SHIFT)
{
dx *= 0.5;
}
_spinBox->setValue( _spinBox->value() + dx );
// Update position !
_lastMousePos = pos;
}
break;
default:
break;
}
return false;
}
示例11: if
bool ptToolBox::eventFilter(QObject* ASender, QEvent* AEvent) {
if (ASender == FHelpIcon && AEvent->type() == QEvent::MouseButtonRelease) {
QMouseEvent* e = (QMouseEvent*)AEvent;
if (e->button() == Qt::LeftButton) {
QDesktopServices::openUrl(QUrl(FFilter->helpUri()));
return true;
} else {
return false;
}
} else if (ASender == FHeaderWidget && AEvent->type() == QEvent::MouseButtonRelease) {
QMouseEvent* hEvent = (QMouseEvent*)AEvent;
if (hEvent->button() == Qt::LeftButton && hEvent->modifiers() == Qt::NoModifier) {
toggleFolded();
return true;
} else if (hEvent->button() == Qt::LeftButton && hEvent->modifiers() == Qt::ControlModifier) {
// toggle block
createMenuActions();
FBlockAction->activate(QAction::Trigger);
return true;
} else if (hEvent->button() == Qt::RightButton) {
// context menu
execContextMenu(hEvent->globalPos());
return true;
} else {
return false;
}
} else {
return QWidget::eventFilter(ASender, AEvent);
}
}
示例12: buffer
bool WebPage::event(QEvent *ev)
{
QMouseEvent* mouseEvent = NULL;
QWheelEvent* wheelEvent = NULL;
QKeyEvent* keyEvent = NULL;
QByteArray byteArray;
QBuffer buffer(&byteArray);
buffer.open(QIODevice::ReadWrite);
QDataStream out(&buffer);
out << (int) ev->type();
switch (ev->type()) {
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
if (OPNET::OpNetwork::instance()->isReplay() || OPNET::OpNetwork::instance()->isReplica())
return false;
mouseEvent = (static_cast<QMouseEvent*>(ev));
out << mouseEvent->pos() << mouseEvent->globalPos()
<< (int) mouseEvent->button() << (int) mouseEvent->buttons()
<< (int) mouseEvent->modifiers();
OPNET::OpNetwork::instance()->sendSysCall(MSG_LOG_USER_INPUT, (int) ev->type(), byteArray);
break;
case QEvent::Wheel:
if (OPNET::OpNetwork::instance()->isReplay() || OPNET::OpNetwork::instance()->isReplica())
return false;;
wheelEvent = (static_cast<QWheelEvent*>(ev));
out << wheelEvent->pos() << wheelEvent->globalPos()
<< wheelEvent->delta() << (int) wheelEvent->buttons()
<< (int) wheelEvent->modifiers() << (int) wheelEvent->orientation();
OPNET::OpNetwork::instance()->sendSysCall(MSG_LOG_USER_INPUT, (int) ev->type(), byteArray);
break;
case QEvent::KeyPress:
case QEvent::KeyRelease:
if (OPNET::OpNetwork::instance()->isReplay() || OPNET::OpNetwork::instance()->isReplica())
return false;
keyEvent = (static_cast<QKeyEvent*>(ev));
out << keyEvent->key() << (int) keyEvent->modifiers()
<< keyEvent->text() << keyEvent->isAutoRepeat()
<< (int) keyEvent->count();
OPNET::OpNetwork::instance()->sendSysCall(MSG_LOG_USER_INPUT, (int) ev->type(), byteArray);
break;
default:
break;
}
return QWebPage::event(ev);
}
示例13: findPathGraph
bool scissor::eventFilter(QObject *obj, QEvent *event)
{
if(qobject_cast<QLabel*>(obj)==ui->label &&event->type() == QEvent::MouseButtonPress)
{
cout<<"click"<<endl;
if(Is_start)
{
Is_graphed = 0;
if(!Init_seed)
{
seed_vector.clear();
fullPath_vector.clear();
shortPath_vector.clear();
cout<<"init_seed"<<endl;
Init_seed = 1;
}
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
int x = mouseEvent->pos().y();
int y =mouseEvent->pos().x();
cout<<"mouse click "<<x<<" "<<y<<endl;
if(x < image.rows && y < image.cols)
if(!Is_closed)
findPathGraph(x,y);
else
if(Is_mask)
getMask(x,y);
closeDetect(x,y);
}
}
if (qobject_cast<QLabel*>(obj)==ui->label &&event->type() == QEvent::MouseMove)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
statusBar()->showMessage(QString("Mouse move (%1,%2)").arg(mouseEvent->pos().y()).arg(mouseEvent->pos().x()));
if(Is_graphed == 1)
{
int x = mouseEvent->pos().y();
int y = mouseEvent->pos().x();
//cout<<"x "<<x<<"y "<<y<<endl;
if(x < image.rows && y < image.cols && !Is_closed)
{
moveMouse(x,y);
cout<<"move mouse"<<x<<" " <<y <<endl;
}
}
}
return false;
}
示例14: QMouseEvent
void EWAUserAction::execute( QWebView *webViewPtr ) const
{
if( !webViewPtr )
{
return;
}
//EWAWebView *pEwaWebView = qobject_cast<EWAWebView*>( webViewPtr );
//bool bNeedSetFocus = false;
QEvent *pEventCopy = 0;
if( isMouseEvent( m_pEvent->type() ) )
{
QMouseEvent *pSrcMouseEvent = static_cast<QMouseEvent *>( m_pEvent );
QPoint clickCoords = pSrcMouseEvent->pos();
pEventCopy = new QMouseEvent(
pSrcMouseEvent->type(),
clickCoords,
webViewPtr->mapToGlobal( clickCoords ),
pSrcMouseEvent->button(),
pSrcMouseEvent->buttons(),
pSrcMouseEvent->modifiers() );
}
else if( isKeyEvent( m_pEvent->type() ) )
{
QKeyEvent *pSrcKeyEvent = static_cast<QKeyEvent*>( m_pEvent );
pEventCopy = new QKeyEvent(
pSrcKeyEvent->type(),
pSrcKeyEvent->key(),
pSrcKeyEvent->modifiers(),
pSrcKeyEvent->text(),
pSrcKeyEvent->isAutoRepeat(),
pSrcKeyEvent->count() );
}
if( pEventCopy )
{
QSize dstSz = getWebViewSize();
if( webViewPtr->page()->preferredContentsSize() != dstSz )
{
webViewPtr->page()->setPreferredContentsSize( dstSz );
}
EWAApplication::postEvent( webViewPtr, pEventCopy );
}
}
示例15: switch
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 );
}