本文整理汇总了C++中QContextMenuEvent::reason方法的典型用法代码示例。如果您正苦于以下问题:C++ QContextMenuEvent::reason方法的具体用法?C++ QContextMenuEvent::reason怎么用?C++ QContextMenuEvent::reason使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QContextMenuEvent
的用法示例。
在下文中一共展示了QContextMenuEvent::reason方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool QToolBoxHelper::eventFilter(QObject *watched, QEvent *event)
{
switch (event->type()) {
case QEvent::ChildPolished:
// Install on the buttons
if (watched == m_toolbox) {
QChildEvent *ce = static_cast<QChildEvent *>(event);
if (!qstrcmp(ce->child()->metaObject()->className(), "QToolBoxButton"))
ce->child()->installEventFilter(this);
}
break;
case QEvent::ContextMenu:
if (watched != m_toolbox) {
// An action invoked from the passive interactor (ToolBox button) might
// cause its deletion within its event handler, triggering a warning. Re-post
// the event to the toolbox.
QContextMenuEvent *current = static_cast<QContextMenuEvent *>(event);
QContextMenuEvent *copy = new QContextMenuEvent(current->reason(), current->pos(), current-> globalPos(), current->modifiers());
QApplication::postEvent(m_toolbox, copy);
current->accept();
return true;
}
break;
case QEvent::MouseButtonRelease:
if (watched != m_toolbox)
if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(m_toolbox)) {
fw->clearSelection();
fw->selectWidget(m_toolbox, true);
}
break;
default:
break;
}
return QObject::eventFilter(watched, event);
}
示例2: event
bool FrameShadowBase::event(QEvent* e) {
// paintEvents are handled separately
if (e->type() == QEvent::Paint)
return QWidget::event(e);
QWidget* viewport(FrameShadowBase::viewport());
switch (e->type()) {
case QEvent::DragEnter:
case QEvent::DragMove:
case QEvent::DragLeave:
case QEvent::Drop:
if ( viewport ) {
setAcceptDrops(viewport->acceptDrops());
return viewport->QObject::event(e);
}
break;
case QEvent::Enter:
if ( viewport ) {
setCursor(viewport->cursor());
setAcceptDrops(viewport->acceptDrops());
}
break;
case QEvent::ContextMenu:
if ( viewport ) {
QContextMenuEvent* me = static_cast<QContextMenuEvent*>(e);
QContextMenuEvent* ne = new QContextMenuEvent(me->reason(), parentWidget()->mapFromGlobal(me->globalPos()), me->globalPos());
QApplication::sendEvent(viewport, ne);
e->accept();
return true;
}
break;
case QEvent::MouseButtonPress:
releaseMouse();
case QEvent::MouseMove:
case QEvent::MouseButtonRelease:
if ( viewport ) {
QMouseEvent* me = static_cast<QMouseEvent*>(e);
QMouseEvent* ne = new QMouseEvent(e->type(), parentWidget()->mapFromGlobal(me->globalPos()), me->globalPos(), me->button(), me->buttons(), me->modifiers());
QApplication::sendEvent(viewport, ne);
e->accept();
return true;
}
break;
default:
break;
}
e->ignore();
return false;
}
示例3: eventFilter
bool StayPoppedUpComboBox::eventFilter(QObject* o, QEvent* e)
{
// The combo box has installed an event filter on the view.
// If it catches a valid mouse button release there, it will hide the popup.
// Here we prevent this by eating the event ourselves,
// and then dispatching it to its destination.
if (o == m_view || o == m_view->viewport())
{
switch (e->type())
{
case QEvent::MouseButtonRelease:
{
QMouseEvent* m = static_cast<QMouseEvent*>(e);
if (m_view->isVisible() && m_view->rect().contains(m->pos()))
{
if (o == m_view)
{
o->event(e);
}
else
// Viewport: Calling event() does not work, viewportEvent() is needed.
// This is the event that gets redirected to the QTreeView finally!
{
sendViewportEventToView(e);
}
// we have dispatched the event privately; we filter it out from the main dispatching
return true;
}
break;
}
case QEvent::ContextMenu:
{
if (o != m_view)
{
// for whatever reason, the position of the event is slightly wrong
QContextMenuEvent* m = static_cast<QContextMenuEvent*>(e);
QPoint correctPos = m_view->viewport()->mapFromGlobal(m->globalPos());
QContextMenuEvent corrected(m->reason(), correctPos, m->globalPos(), m->modifiers());
sendViewportEventToView(&corrected);
return true;
}
break;
}
default:
break;
}
}
return QComboBox::eventFilter(o, e);
}
示例4: event
bool GoBackActionWidget::event(QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::Wheel)
{
QList<GesturesManager::GesturesContext> contexts;
contexts << GesturesManager::ToolBarGesturesContext << GesturesManager::GenericGesturesContext;
if (GesturesManager::startGesture(this, event, contexts))
{
return true;
}
}
if (event->type() == QEvent::ContextMenu)
{
QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent*>(event);
if (contextMenuEvent)
{
if (contextMenuEvent->reason() == QContextMenuEvent::Mouse)
{
contextMenuEvent->accept();
return true;
}
event->accept();
Window *window = getWindow();
QMenu menu(this);
menu.addAction(window ? window->getContentsWidget()->getAction(ActionsManager::ClearTabHistoryAction) : ActionsManager::getAction(ActionsManager::ClearTabHistoryAction, this));
menu.addAction(window ? window->getContentsWidget()->getAction(ActionsManager::PurgeTabHistoryAction) : ActionsManager::getAction(ActionsManager::PurgeTabHistoryAction, this));
ToolBarWidget *toolBar = qobject_cast<ToolBarWidget*>(parentWidget());
if (toolBar)
{
menu.addSeparator();
menu.addActions(ToolBarWidget::createCustomizationMenu(toolBar->getIdentifier(), QList<QAction*>(), &menu)->actions());
}
menu.exec(contextMenuEvent->globalPos());
return true;
}
return false;
}
if (event->type() == QEvent::ToolTip)
{
QHelpEvent *helpEvent = dynamic_cast<QHelpEvent*>(event);
if (helpEvent)
{
const QVector<QKeySequence> shortcuts = ActionsManager::getActionDefinition(ActionsManager::GoBackAction).shortcuts;
QString toolTip = text() + (shortcuts.isEmpty() ? QString() : QLatin1String(" (") + shortcuts.at(0).toString(QKeySequence::NativeText) + QLatin1Char(')'));
if (getWindow())
{
const WindowHistoryInformation history = getWindow()->getContentsWidget()->getHistory();
if (!history.entries.isEmpty() && history.index > 0)
{
QString title = history.entries.at(history.index - 1).title;
title = (title.isEmpty() ? tr("(Untitled)") : title.replace(QLatin1Char('&'), QLatin1String("&&")));
toolTip = title + QLatin1String(" (") + text() + (shortcuts.isEmpty() ? QString() : QLatin1String(" - ") + shortcuts.at(0).toString(QKeySequence::NativeText)) + QLatin1Char(')');
}
}
QToolTip::showText(helpEvent->globalPos(), toolTip);
}
return true;
}
return ActionWidget::event(event);
}
示例5: event
bool KrTreeWidget::event(QEvent * event)
{
switch (event->type()) {
// HACK: QT 4 Context menu key isn't handled properly
case QEvent::ContextMenu: {
QContextMenuEvent* ce = (QContextMenuEvent*) event;
if (ce->reason() == QContextMenuEvent::Mouse) {
QPoint pos = viewport()->mapFromGlobal(ce->globalPos());
QTreeWidgetItem * item = itemAt(pos);
int column = columnAt(pos.x());
emit itemRightClicked(item, ce->globalPos(), column);
return true;
} else {
if (currentItem()) {
QRect r = visualItemRect(currentItem());
QPoint p = viewport()->mapToGlobal(QPoint(r.x() + 5, r.y() + 5));
emit itemRightClicked(currentItem(), p, currentColumn());
return true;
}
}
}
break;
case QEvent::KeyPress: {
// HACK: QT 4 Ctrl+A bug fix: Ctrl+A doesn't work if QTreeWidget contains parent / child items
// Insert doesn't change the selections for multi selection modes
QKeyEvent* ke = (QKeyEvent*) event;
switch (ke->key()) {
case Qt::Key_Insert: {
if (ke->modifiers() != 0)
break;
QAbstractItemView::SelectionMode mode = selectionMode();
if (mode != QAbstractItemView::ContiguousSelection && mode != QAbstractItemView::ExtendedSelection &&
mode != QAbstractItemView::MultiSelection)
break;
ke->accept();
if (currentItem() == 0)
return true;
currentItem()->setSelected(!currentItem()->isSelected());
return true;
}
case Qt::Key_A:
if (ke->modifiers() == Qt::ControlModifier) {
QAbstractItemView::SelectionMode mode = selectionMode();
if (mode == QAbstractItemView::ContiguousSelection || mode == QAbstractItemView::ExtendedSelection ||
mode == QAbstractItemView::MultiSelection) {
selectAll();
ke->accept();
return true;
}
}
break;
default:
break;
}
}
break;
case QEvent::Resize: {
QResizeEvent * re = (QResizeEvent *)event;
if (!_inResize && re->oldSize() != re->size()) {
if (_stretchingColumn != -1 && columnCount()) {
QList< int > columnsSizes;
int oldSize = 0;
for (int i = 0; i != header()->count(); i++) {
columnsSizes.append(header()->sectionSize(i));
oldSize += header()->sectionSize(i);
}
bool res = QTreeWidget::event(event);
int newSize = viewport()->width();
int delta = newSize - oldSize;
if (delta) {
_inResize = true;
for (int i = 0; i != header()->count(); i++) {
if (i == _stretchingColumn) {
int newNs = columnsSizes[ i ] + delta;
if (newNs < 8)
newNs = 8;
header()->resizeSection(i, newNs);
} else if (header()->sectionSize(i) != columnsSizes[ i ]) {
header()->resizeSection(i, columnsSizes[ i ]);
}
}
_inResize = false;
}
return res;
}
//.........这里部分代码省略.........