本文整理汇总了C++中QWidget::isActiveWindow方法的典型用法代码示例。如果您正苦于以下问题:C++ QWidget::isActiveWindow方法的具体用法?C++ QWidget::isActiveWindow怎么用?C++ QWidget::isActiveWindow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWidget
的用法示例。
在下文中一共展示了QWidget::isActiveWindow方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setState
void TransparentPlugin::setState()
{
QWidget *main = getMainWindow();
if (main == NULL)
return;
#ifdef WIN32
if (timer == NULL){
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(tick()));
main->installEventFilter(this);
SetWindowLongW(main->winId(), GWL_EXSTYLE, GetWindowLongW(main->winId(), GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(main->winId(), main->colorGroup().background().rgb(), 0, LWA_ALPHA);
RedrawWindow(main->winId(), NULL, NULL, RDW_UPDATENOW);
main->setMouseTracking(true);
m_bState = !main->isActiveWindow();
}
bool bNewState = main->isActiveWindow();
if (bNewState == m_bState){
BYTE d = bNewState ? 255 : QMIN((100 - getTransparency()) * 256 / 100, 255);
SetLayeredWindowAttributes(main->winId(), main->colorGroup().background().rgb(), d, LWA_ALPHA);
return;
}
m_bState = bNewState;
startTime = GetTickCount();
timer->start(10);
#else
if (top == NULL)
top = new TransparentTop(main, getTransparency());
top->setTransparent(getTransparency());
#endif
}
示例2: onAboutToShow
void WindowMenu::onAboutToShow()
{
QWidget* win = QApplication::activeWindow();
pMinimize_->setEnabled(win);
pZoom_->setEnabled(win && win->maximumSize() != win->minimumSize());
pBringAllToFront_->setEnabled(win);
for (int i = windows_.size() - 1; i >= 0; i--)
{
QAction* pAction = windows_[i];
removeAction(pAction);
windows_.removeAt(i);
pAction->deleteLater();
}
QWidgetList topLevels = QApplication::topLevelWidgets();
for (int i = 0; i < topLevels.size(); i++)
{
QWidget* pWindow = topLevels.at(i);
if (!pWindow->isVisible())
continue;
QAction* pAction = new QAction(pWindow->windowTitle(), pWindow);
pAction->setData(QVariant::fromValue(pWindow));
pAction->setCheckable(true);
if (pWindow->isActiveWindow())
pAction->setChecked(true);
insertAction(pWindowPlaceholder_, pAction);
connect(pAction, SIGNAL(triggered()),
this, SLOT(showWindow()));
windows_.append(pAction);
}
}
示例3: state
/*! \reimp */
QAccessible::State QAccessibleWidget::state(int child) const
{
if (child)
return Normal;
QAccessible::State state = Normal;
QWidget *w = widget();
if (w->testAttribute(Qt::WA_WState_Visible) == false)
state |= Invisible;
if (w->focusPolicy() != Qt::NoFocus && w->isActiveWindow())
state |= Focusable;
if (w->hasFocus())
state |= Focused;
if (!w->isEnabled())
state |= Unavailable;
if (w->isWindow()) {
if (w->windowFlags() & Qt::WindowSystemMenuHint)
state |= Movable;
if (w->minimumSize() != w->maximumSize())
state |= Sizeable;
}
return state;
}
示例4: eventFilter
bool QPropertyDelegate::eventFilter(QObject *object, QEvent *event)
{
QWidget *editor = ::qobject_cast<QWidget*>(object);
if(!editor)
return false;
GD_ASSERT(editor == mActiveEditor);
if(event->type() == QEvent::KeyPress)
{
switch(static_cast<QKeyEvent *>(event)->key())
{
case Qt::Key_Tab:
emit commitData(editor);
emit closeEditor(editor, QAbstractItemDelegate::EditNextItem);
mActiveEditor = 0;
return true;
case Qt::Key_Backtab:
emit commitData(editor);
emit closeEditor(editor, QAbstractItemDelegate::EditPreviousItem);
mActiveEditor = 0;
return true;
case Qt::Key_Enter:
case Qt::Key_Return:
emit commitData(editor);
emit closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
mActiveEditor = 0;
return true;
case Qt::Key_Escape:
// don't commit data
emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
mActiveEditor = 0;
return true;
default:
break;
}
}
else if(event->type() == QEvent::FocusOut && !editor->isActiveWindow())
{
#ifndef QT_NO_DRAGANDDROP
// The window may loose focus during an drag operation.
// i.e when dragging involves the task bar on Windows.
//if(QDragManager::self() && QDragManager::self()->object != 0)
// return false;
#endif
if( QApplication::activeModalWidget() && QApplication::activeModalWidget()->parent() == editor )
return true;
emit commitData(editor);
emit closeEditor(editor, NoHint);
mActiveEditor = 0;
return true;
}
return false;
}
示例5: isActiveChatWindow
bool TabWidget::isActiveChatWindow()
{
QWidget *widget = m_self->parentWidget();
if (widget->isMinimized() || widget->isHidden())
return false;
# if defined(Q_OS_WIN32)
if (widget->isActiveWindow()) {
HWND active = GetForegroundWindow();
if (active == (HWND) widget->window()->internalWinId() || ::IsChild(active, (HWND) widget->window()->internalWinId()))
return true;
else
return false;
}
else
return false;
# else
return widget->isActiveWindow();
# endif
}
示例6: testActivation
void tst_QWindowContainer::testActivation()
{
QWidget root;
QWindow *window = new QWindow();
QWidget *container = QWidget::createWindowContainer(window, &root);
container->setGeometry(100, 100, 200, 100);
root.setGeometry(100, 100, 400, 300);
root.show();
root.activateWindow();
QVERIFY(QTest::qWaitForWindowExposed(&root));
QVERIFY(QTest::qWaitForWindowActive(root.windowHandle()));
QVERIFY(QGuiApplication::focusWindow() == root.windowHandle());
// Verify that all states in the root widget indicate it is active
QVERIFY(root.windowHandle()->isActive());
QVERIFY(root.isActiveWindow());
QCOMPARE(root.palette().currentColorGroup(), QPalette::Active);
// Under KDE (ubuntu 12.10), we experience that doing two activateWindow in a row
// does not work. The second gets ignored by the window manager, even though the
// timestamp in the xcb connection is unique for both.
if (QGuiApplication::platformName() == "xcb")
QTest::qWait(100);
window->requestActivate();
QTRY_VERIFY(QGuiApplication::focusWindow() == window);
// Verify that all states in the root widget still indicate it is active
QVERIFY(root.windowHandle()->isActive());
QVERIFY(root.isActiveWindow());
QCOMPARE(root.palette().currentColorGroup(), QPalette::Active);
}
示例7: transparentChanged
void TransparentTop::transparentChanged()
{
#ifdef WIN32
QWidget *p = static_cast<QWidget*>(parent());
bool bTransparent = true;
if (pMain->TransparentIfInactive) bTransparent = !p->isActiveWindow();
setTransparent(p, useTransparent && bTransparent, transparent);
#endif
#if defined(USE_KDE) && defined(HAVE_KROOTPIXMAP_H)
if (useTransparent){
rootpixmap->start();
}else{
rootpixmap->stop();
saveBG = QPixmap();
genBG = QPixmap();
genFade = 0;
emit backgroundUpdated();
}
#endif
}
示例8: state
/*! \reimp */
QAccessible::State QAccessibleWidget::state() const
{
QAccessible::State state;
QWidget *w = widget();
if (w->testAttribute(Qt::WA_WState_Visible) == false)
state.invisible = true;
if (w->focusPolicy() != Qt::NoFocus)
state.focusable = true;
if (w->hasFocus())
state.focused = true;
if (!w->isEnabled())
state.disabled = true;
if (w->isWindow()) {
if (w->windowFlags() & Qt::WindowSystemMenuHint)
state.movable = true;
if (w->minimumSize() != w->maximumSize())
state.sizeable = true;
if (w->isActiveWindow())
state.active = true;
}
return state;
}
示例9: handleMouseEvent
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
static const QEvent::Type contextMenuTrigger =
QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
if (qApp->d_func()->inPopupMode()) {
QWidget *activePopupWidget = qApp->activePopupWidget();
QWidget *popup = activePopupWidget;
QPoint mapped = event->pos();
if (popup != m_widget)
mapped = popup->mapFromGlobal(event->globalPos());
bool releaseAfter = false;
QWidget *popupChild = popup->childAt(mapped);
if (popup != qt_popup_down) {
qt_button_down = 0;
qt_popup_down = 0;
}
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
qt_button_down = popupChild;
qt_popup_down = popup;
break;
case QEvent::MouseButtonRelease:
releaseAfter = true;
break;
default:
break; // nothing for mouse move
}
int oldOpenPopupCount = openPopupCount;
if (popup->isEnabled()) {
// deliver event
qt_replay_popup_mouse_event = false;
QWidget *receiver = popup;
QPoint widgetPos = mapped;
if (qt_button_down)
receiver = qt_button_down;
else if (popupChild)
receiver = popupChild;
if (receiver != popup)
widgetPos = receiver->mapFromGlobal(event->globalPos());
QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos()));
QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
e.setTimestamp(event->timestamp());
QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver);
} else {
// close disabled popups when a mouse button is pressed or released
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
popup->close();
break;
default:
break;
}
}
if (qApp->activePopupWidget() != activePopupWidget
&& qt_replay_popup_mouse_event) {
if (m_widget->windowType() != Qt::Popup)
qt_button_down = 0;
if (event->type() == QEvent::MouseButtonPress) {
// the popup disappeared, replay the mouse press event
QWidget *w = QApplication::widgetAt(event->globalPos());
if (w && !QApplicationPrivate::isBlockedByModal(w)) {
// activate window of the widget under mouse pointer
if (!w->isActiveWindow()) {
w->activateWindow();
w->raise();
}
QWindow *win = w->windowHandle();
if (!win)
win = w->nativeParentWidget()->windowHandle();
if (win && win->geometry().contains(event->globalPos())) {
const QPoint localPos = win->mapFromGlobal(event->globalPos());
QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
e.setTimestamp(event->timestamp());
QApplication::sendSpontaneousEvent(win, &e);
}
}
}
qt_replay_popup_mouse_event = false;
#ifndef QT_NO_CONTEXTMENU
} else if (event->type() == contextMenuTrigger
&& event->button() == Qt::RightButton
&& (openPopupCount == oldOpenPopupCount)) {
QWidget *popupEvent = popup;
if (qt_button_down)
popupEvent = qt_button_down;
else if(popupChild)
popupEvent = popupChild;
QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
//.........这里部分代码省略.........
示例10: qt_mac_get_save_file_name
QString qt_mac_get_save_file_name(const QFileDialogArgs &args, QString *pwd,
QString *selectedFilter)
{
QWidget *parent = args.parent;
OSErr err;
QString retstr;
NavDialogCreationOptions options;
NavGetDefaultDialogCreationOptions(&options);
static const int w = 450, h = 350;
if (args.options & QFileDialog::DontConfirmOverwrite)
options.optionFlags |= kNavDontConfirmReplacement;
options.modality = kWindowModalityAppModal;
options.location.h = options.location.v = -1;
if (!args.directory.isEmpty())
options.saveFileName = QCFString::toCFStringRef(args.selection);
if (!args.caption.isEmpty())
options.windowTitle = QCFString::toCFStringRef(args.caption);
if (parent && parent->isVisible()) {
WindowClass wclass;
GetWindowClass(qt_mac_window_for(parent), &wclass);
if (!(args.options & QFileDialog::DontUseSheet) && (wclass == kDocumentWindowClass ||
wclass == kFloatingWindowClass || wclass == kMovableModalWindowClass)) {
options.modality = kWindowModalityWindowModal;
options.parentWindow = qt_mac_window_for(parent);
// The parent needs to be active for the sheet to get keyboard focus.
if (!parent->isActiveWindow())
parent->activateWindow();
} else {
parent = parent->window();
QString s = parent->windowTitle();
options.clientName = CFStringCreateWithCharacters(0, (UniChar *)s.unicode(), s.length());
options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);
QRect r = QApplication::desktop()->screenGeometry(
QApplication::desktop()->screenNumber(parent));
if (options.location.h + w > r.right())
options.location.h -= (options.location.h + w) - r.right() + 10;
if (options.location.v + h > r.bottom())
options.location.v -= (options.location.v + h) - r.bottom() + 10;
}
#if 0
} else if (QWidget *p = qApp->mainWidget()) {
static int last_screen = -1;
int scr = QApplication::desktop()->screenNumber(p);
if (last_screen != scr) {
QRect r = QApplication::desktop()->screenGeometry(scr);
options.location.h = (r.x() + (r.width() / 2)) - (w / 2);
options.location.v = (r.y() + (r.height() / 2)) - (h / 2);
}
#endif
}
QList<qt_mac_filter_name*> filts = qt_mac_make_filters_list(args.filter);
qt_mac_nav_filter_type t;
t.saveDialog = true;
t.index = 0;
t.filts = &filts;
if (filts.count() > 1) {
int i = 0;
CFStringRef *arr = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef) * filts.count()));
for (QList<qt_mac_filter_name*>::const_iterator it = filts.constBegin();
it != filts.constEnd(); ++it)
arr[i++] = QCFString::toCFStringRef((*it)->description);
options.popupExtension = CFArrayCreate(0, reinterpret_cast<const void **>(arr), filts.count(), 0);
}
NavDialogRef dlg;
if (NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(),
static_cast<void *>(filts.isEmpty() ? 0 : &t), &dlg)) {
qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
return retstr;
}
if (pwd && !pwd->isEmpty()) {
FSRef fsref;
if (qt_mac_create_fsref(*pwd, &fsref) == noErr) {
AEDesc desc;
if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr)
NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc);
}
}
NavDialogRun(dlg);
if (selectedFilter) {
NavMenuItemSpec navSpec;
bzero(&navSpec, sizeof(NavMenuItemSpec));
qt_mac_filter_name *sel_filt_name = qt_mac_make_filters_list(*selectedFilter).at(0);
for (int i = 0; i < filts.count(); ++i) {
const qt_mac_filter_name *filter = filts.at(i);
if (sel_filt_name->description == filter->description
&& sel_filt_name->regxp == filter->regxp
&& sel_filt_name->filter == filter->filter) {
navSpec.menuType = i;
break;
}
}
NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec);
}
if (options.modality == kWindowModalityWindowModal) { //simulate modality
QWidget modal_widg(parent, Qt::Sheet);
//.........这里部分代码省略.........
示例11: eventFilter
bool CFileListItemDelegate::eventFilter(QObject * object, QEvent * event)
{
QWidget *editor = qobject_cast<QWidget*>(object);
if (!editor)
return false;
if (event->type() == QEvent::KeyPress)
{
switch (static_cast<QKeyEvent *>(event)->key())
{
case Qt::Key_Tab:
emit closeEditor(editor, EditNextItem);
return true;
case Qt::Key_Backtab:
emit closeEditor(editor, EditPreviousItem);
return true;
case Qt::Key_Enter: // Numpad Enter
case Qt::Key_Return:
// don't filter enter key events for QTextEdit
if (!qobject_cast<QTextEdit *>(editor) && !qobject_cast<QPlainTextEdit*>(editor))
{
// commit data
emit commitData(editor);
emit closeEditor(editor);
return true;
}
return QStyledItemDelegate::eventFilter(object, event);
case Qt::Key_Escape:
// don't commit data
emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
return true;
case Qt::Key_Up:
case Qt::Key_Down:
// don't commit data
emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
// Don't consume the event so that the TreeView will handle this event and highlight the next item properly
return QStyledItemDelegate::eventFilter(object, event);
default:
return QStyledItemDelegate::eventFilter(object, event);
}
}
else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow()))
{
//the Hide event will take care of he editors that are in fact complete dialogs
if (!editor->isActiveWindow() || (QApplication::focusWidget() != editor))
{
QWidget *w = QApplication::focusWidget();
while (w)
{ // don't worry about focus changes internally in the editor
if (w == editor)
return QStyledItemDelegate::eventFilter(object, event);
w = w->parentWidget();
}
emit closeEditor(editor, NoHint);
}
}
else if (event->type() == QEvent::ShortcutOverride)
{
if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape)
{
event->accept();
return true;
}
}
return QStyledItemDelegate::eventFilter(object, event);
}
示例12: handleMouseEvent
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
static const QEvent::Type contextMenuTrigger =
QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
if (qApp->d_func()->inPopupMode()) {
QWidget *activePopupWidget = qApp->activePopupWidget();
QPoint mapped = event->pos();
if (activePopupWidget != m_widget)
mapped = activePopupWidget->mapFromGlobal(event->globalPos());
bool releaseAfter = false;
QWidget *popupChild = activePopupWidget->childAt(mapped);
if (activePopupWidget != qt_popup_down) {
qt_button_down = 0;
qt_popup_down = 0;
}
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
qt_button_down = popupChild;
qt_popup_down = activePopupWidget;
break;
case QEvent::MouseButtonRelease:
releaseAfter = true;
break;
default:
break; // nothing for mouse move
}
int oldOpenPopupCount = openPopupCount;
if (activePopupWidget->isEnabled()) {
// deliver event
qt_replay_popup_mouse_event = false;
QWidget *receiver = activePopupWidget;
QPoint widgetPos = mapped;
if (qt_button_down)
receiver = qt_button_down;
else if (popupChild)
receiver = popupChild;
if (receiver != activePopupWidget)
widgetPos = receiver->mapFromGlobal(event->globalPos());
QWidget *alien = receiver;
#if !defined(Q_OS_OSX) && !defined(Q_OS_IOS) // Cocoa tracks popups
const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped);
const bool underMouse = activePopupWidget->underMouse();
if (activePopupWidget != m_widget || (!underMouse && qt_button_down)) {
// If active popup menu is not the first-level popup menu then we must emulate enter/leave events,
// because first-level popup menu grabs the mouse and enter/leave events are delivered only to it
// by QPA. Make an exception for first-level popup menu when the mouse button is pressed on widget.
if (underMouse != reallyUnderMouse) {
if (reallyUnderMouse) {
QApplicationPrivate::dispatchEnterLeave(receiver, Q_NULLPTR, event->screenPos());
qt_last_mouse_receiver = receiver;
} else {
QApplicationPrivate::dispatchEnterLeave(Q_NULLPTR, qt_last_mouse_receiver, event->screenPos());
qt_last_mouse_receiver = receiver;
receiver = activePopupWidget;
}
}
} else if (!reallyUnderMouse) {
alien = Q_NULLPTR;
}
#endif
QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(),
event->button(), event->buttons(), event->modifiers(), event->source());
e.setTimestamp(event->timestamp());
QApplicationPrivate::sendMouseEvent(receiver, &e, alien, receiver->window(), &qt_button_down, qt_last_mouse_receiver);
qt_last_mouse_receiver = receiver;
} else {
// close disabled popups when a mouse button is pressed or released
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
activePopupWidget->close();
break;
default:
break;
}
}
if (qApp->activePopupWidget() != activePopupWidget
&& qt_replay_popup_mouse_event
&& QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ReplayMousePressOutsidePopup).toBool()) {
if (m_widget->windowType() != Qt::Popup)
qt_button_down = 0;
if (event->type() == QEvent::MouseButtonPress) {
// the popup disappeared, replay the mouse press event
QWidget *w = QApplication::widgetAt(event->globalPos());
if (w && !QApplicationPrivate::isBlockedByModal(w)) {
// activate window of the widget under mouse pointer
if (!w->isActiveWindow()) {
w->activateWindow();
w->raise();
}
//.........这里部分代码省略.........