本文整理汇总了C++中QWidget::focusWidget方法的典型用法代码示例。如果您正苦于以下问题:C++ QWidget::focusWidget方法的具体用法?C++ QWidget::focusWidget怎么用?C++ QWidget::focusWidget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWidget
的用法示例。
在下文中一共展示了QWidget::focusWidget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: currentChanged
void GuiMainWindow::currentChanged(int index)
{
if (index < 0)
return;
if (index < (signed)widgetAtIndex.size()) {
auto it = widgetAtIndex[index];
if (it.first) {
if (it.first->focusWidget())
it.first->focusWidget()->setFocus();
} else if (it.second)
it.second->setFocus();
return;
}
// slow_mode: if tab is inserted just now, widgetAtIndex may not
// be up-to-date.
if (tabArea->widget(index)) {
QWidget *currWgt = tabArea->widget(index);
if (qobject_cast<GuiSplitter*>(currWgt)) {
if (currWgt->focusWidget())
currWgt->focusWidget()->setFocus();
} else if (qobject_cast<GuiTerminalWindow*>(currWgt))
currWgt->setFocus();
}
}
示例2: processKeyEvent
void QApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
{
QWidget *focusW = 0;
if (self->inPopupMode()) {
QWidget *popupW = qApp->activePopupWidget();
focusW = popupW->focusWidget() ? popupW->focusWidget() : popupW;
}
if (!focusW)
focusW = QApplication::focusWidget();
if (!focusW) {
focusW = e->widget.data();
}
if (!focusW)
focusW = QApplication::activeWindow();
//qDebug() << "handleKeyEvent" << hex << e->key() << e->modifiers() << e->text() << "widget" << focusW;
if (!focusW)
return;
if (app_do_modal && !qt_try_modal(focusW, e->keyType))
return;
if (e->nativeScanCode || e->nativeVirtualKey || e->nativeModifiers) {
QKeyEventEx ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount,
e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers);
QApplication::sendSpontaneousEvent(focusW, &ev);
} else {
QKeyEvent ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount);
QApplication::sendSpontaneousEvent(focusW, &ev);
}
}
示例3: changedTabPanel
void PrefsDialog::changedTabPanel(int index)
{
// this all feels a bit hacky, but seems to keep things tidy on Mac OS X at least
QWidget *page = tabWidget->widget(index);
page->clearFocus();
switch (index) {
case 0: // General
if (page->focusWidget() != NULL)
page->focusWidget()->clearFocus();
break;
case 1: // Editor
editorFont->setFocus();
editorFont->lineEdit()->selectAll();
break;
case 2: // Preview
scale->setFocus();
scale->selectAll();
break;
case 3: // Typesetting
binPathList->setFocus();
break;
case 4: // Script
if (page->focusWidget() != NULL)
page->focusWidget()->clearFocus();
break;
}
}
示例4: currentChanged
void GuiMainWindow::currentChanged(int index)
{
if (index!=-1 && tabArea->widget(index)) {
QWidget *currWgt = tabArea->widget(index);
if (dynamic_cast<GuiSplitter*>(currWgt)) {
if (currWgt->focusWidget())
currWgt->focusWidget()->setFocus();
} else if (dynamic_cast<GuiTerminalWindow*>(currWgt))
currWgt->setFocus();
}
}
示例5: testMoveTab
void testMoveTab()
{
// Test inspired by #170470 and #177036 (title messup).
// Then expanded to include the problem of #159295 (focus loss).
QWidget topLevel;
QComboBox* combo = new QComboBox(&topLevel);
combo->setEditable(true);
KTabWidget* w = new KTabWidget(&topLevel);
w->setAutomaticResizeTabs(true);
w->resize(300, 400);
QResizeEvent e(w->size(), QSize());
QApplication::sendEvent(w, &e);
QString prefix = "This is a long prefix for the tab title. ";
KLineEdit* lineEdits[4];
for (int i = 0; i < 4; ++i) {
QWidget* page = new QWidget;
page->setObjectName(QString::number(i));
lineEdits[i] = new KLineEdit(page); // a widget that can take focus
lineEdits[i]->setObjectName("LineEdit"+QString::number(i));
w->insertTab(i, page, prefix+QString::number(i));
//kDebug() << i << w->tabText(i);
}
topLevel.show();
// Necessary after show(), otherwise topLevel.focusWidget() returns NULL
QApplication::setActiveWindow(&topLevel);
// Make sure the tab order is so that the combo gets focus after this tab
QWidget::setTabOrder(lineEdits[0], combo->lineEdit());
QWidget::setTabOrder(combo->lineEdit(), lineEdits[1]);
w->setCurrentIndex(0);
lineEdits[0]->setFocus();
QCOMPARE(topLevel.focusWidget()->objectName(), lineEdits[0]->objectName());
QVERIFY(lineEdits[0]->isVisible());
w->moveTab(0,3);
//for (int i = 0; i < 4; ++i)
//kDebug() << i << w->tabText(i);
QCOMPARE(w->tabText(0), QString(prefix+QString::number(1)));
QCOMPARE(w->tabText(1), QString(prefix+QString::number(2)));
QCOMPARE(w->tabText(2), QString(prefix+QString::number(3)));
QCOMPARE(w->tabText(3), QString(prefix+QString::number(0)));
// Did the focus switch to the lineEdit, due to removeTab+insertTab? Whoops.
QCOMPARE(topLevel.focusWidget()->objectName(), lineEdits[0]->objectName());
w->moveTab(3,0);
QCOMPARE(topLevel.focusWidget()->objectName(), lineEdits[0]->objectName());
for (int i = 0; i < 4; ++i) {
//kDebug() << i << w->tabText(i);
QCOMPARE(w->tabText(i), QString(prefix+QString::number(i)));
}
}
示例6:
QWidget *QWidgetProto::focusWidget() const
{
QWidget *item = qscriptvalue_cast<QWidget*>(thisObject());
if (item)
return item->focusWidget();
return 0;
}
示例7: setFocusProxy
SearchBar::SearchBar(QWidget *parent)
:QWidget(parent)
{
// Get the widget that currently has the focus so we can properly
// restore it when the filter bar is closed.
QWidget* widgetWindow = (parent ? parent->window() : 0);
m_focusWidget = (widgetWindow ? widgetWindow->focusWidget() : 0);
// Initialize the user interface...
m_ui.setupUi(this);
m_ui.optionsButton->addAction(m_ui.actionMatchCase);
m_ui.optionsButton->addAction(m_ui.actionHighlightMatch);
m_ui.optionsButton->addAction(m_ui.actionSearchAutomatically);
m_ui.closeButton->setIcon(KIcon("dialog-close"));
m_ui.previousButton->setIcon(KIcon("go-up-search"));
m_ui.nextButton->setIcon(KIcon("go-down-search"));
m_ui.previousButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_ui.nextButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_ui.searchInfo->setText(i18nc("label for input line to find text", "&Find:"));
setFocusProxy(m_ui.searchComboBox);
connect(m_ui.nextButton, SIGNAL(clicked()),
this, SLOT(findNext()));
connect(m_ui.previousButton, SIGNAL(clicked()),
this, SLOT(findPrevious()));
connect(m_ui.searchComboBox, SIGNAL(returnPressed()),
this, SLOT(findNext()));
connect(m_ui.searchComboBox, SIGNAL(editTextChanged(QString)),
this, SLOT(textChanged(QString)));
// Start off hidden by default...
setVisible(false);
}
示例8: setCurrentIndex
/*!
\property QStackedLayout::currentIndex
\brief the index position of the widget that is visible
The current index is -1 if there is no current widget.
\sa currentWidget(), indexOf()
*/
void QStackedLayout::setCurrentIndex(int index)
{
Q_D(QStackedLayout);
QWidget *prev = currentWidget();
QWidget *next = widget(index);
if (!next || next == prev)
return;
bool reenableUpdates = false;
QWidget *parent = parentWidget();
if (parent && parent->updatesEnabled()) {
reenableUpdates = true;
parent->setUpdatesEnabled(false);
}
QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0;
const bool focusWasOnOldPage = fw && (prev && prev->isAncestorOf(fw));
if (prev) {
prev->clearFocus();
if (d->stackingMode == StackOne)
prev->hide();
}
d->index = index;
next->raise();
next->show();
// try to move focus onto the incoming widget if focus
// was somewhere on the outgoing widget.
if (parent) {
if (focusWasOnOldPage) {
// look for the best focus widget we can find
if (QWidget *nfw = next->focusWidget())
nfw->setFocus();
else {
// second best: first child widget in the focus chain
if (QWidget *i = fw) {
while ((i = i->nextInFocusChain()) != fw) {
if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
&& !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
&& next->isAncestorOf(i)) {
i->setFocus();
break;
}
}
// third best: incoming widget
if (i == fw )
next->setFocus();
}
}
}
}
if (reenableUpdates)
parent->setUpdatesEnabled(true);
emit currentChanged(index);
}
示例9: closePopup
void QApplicationPrivate::closePopup(QWidget *popup)
{
if (!popupWidgets)
return;
popupWidgets->removeAll(popup);
if (popup == qt_popup_down) {
qt_button_down = 0;
qt_popup_down = 0;
}
if (QApplicationPrivate::popupWidgets->count() == 0) { // this was the last popup
delete QApplicationPrivate::popupWidgets;
QApplicationPrivate::popupWidgets = 0;
if (popupGrabOk) {
popupGrabOk = false;
if (popup->geometry().contains(QPoint(QGuiApplicationPrivate::mousePressX,
QGuiApplicationPrivate::mousePressY))
|| popup->testAttribute(Qt::WA_NoMouseReplay)) {
// mouse release event or inside
qt_replay_popup_mouse_event = false;
} else { // mouse press event
QGuiApplicationPrivate::mousePressTime -= 10000; // avoid double click
qt_replay_popup_mouse_event = true;
}
// transfer grab back to mouse grabber if any, otherwise release the grab
ungrabMouseForPopup(popup);
// transfer grab back to keyboard grabber if any, otherwise release the grab
ungrabKeyboardForPopup(popup);
}
if (active_window) {
if (QWidget *fw = active_window->focusWidget()) {
if (fw != QApplication::focusWidget()) {
fw->setFocus(Qt::PopupFocusReason);
} else {
QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
QCoreApplication::sendEvent(fw, &e);
}
}
}
} else {
// A popup was closed, so the previous popup gets the focus.
QWidget* aw = QApplicationPrivate::popupWidgets->last();
if (QWidget *fw = aw->focusWidget())
fw->setFocus(Qt::PopupFocusReason);
if (QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard
grabForPopup(aw);
}
}
示例10:
GuiTerminalWindow * GuiMainWindow::getCurrentTerminal()
{
GuiTerminalWindow *termWindow;
QWidget *widget = tabArea->currentWidget();
if (!widget)
return NULL;
termWindow = dynamic_cast<GuiTerminalWindow*>(widget->focusWidget());
if (!termWindow || terminalList.indexOf(termWindow) == -1)
return NULL;
return termWindow;
}
示例11: setFocusToCurrentMode
void ModeManager::setFocusToCurrentMode()
{
IMode *mode = findMode(currentMode());
QTC_ASSERT(mode, return);
QWidget *widget = mode->widget();
if (widget) {
QWidget *focusWidget = widget->focusWidget();
if (!focusWidget)
focusWidget = widget;
focusWidget->setFocus();
}
}
示例12: setFocusToCurrentMode
void ModeManager::setFocusToCurrentMode()
{
IMode *mode = currentMode();
QTC_ASSERT(mode, return);
QWidget *widget = mode->widget();
if (widget) {
QWidget *focusWidget = widget->focusWidget();
if (!focusWidget)
focusWidget = widget;
focusWidget->setFocus();
ICore::raiseWindow(focusWidget);
}
}
示例13: closePopup
void QApplicationPrivate::closePopup(QWidget *popup)
{
Q_Q(QApplication);
if (!popupWidgets)
return;
popupWidgets->removeAll(popup);
//###
// if (popup == qt_popup_down) {
// qt_button_down = 0;
// qt_popup_down = 0;
// }
if (QApplicationPrivate::popupWidgets->count() == 0) { // this was the last popup
delete QApplicationPrivate::popupWidgets;
QApplicationPrivate::popupWidgets = 0;
//### replay mouse event?
//### transfer/release mouse grab
//### transfer/release keyboard grab
//give back focus
if (active_window) {
if (QWidget *fw = active_window->focusWidget()) {
if (fw != QApplication::focusWidget()) {
fw->setFocus(Qt::PopupFocusReason);
} else {
QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
q->sendEvent(fw, &e);
}
}
}
} else {
// A popup was closed, so the previous popup gets the focus.
QWidget* aw = QApplicationPrivate::popupWidgets->last();
if (QWidget *fw = aw->focusWidget())
fw->setFocus(Qt::PopupFocusReason);
//### regrab the keyboard and mouse in case 'popup' lost the grab
}
}
示例14: handleKeyEvent
void QWidgetWindow::handleKeyEvent(QKeyEvent *event)
{
if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
return;
QObject *receiver = QWidget::keyboardGrabber();
if (!receiver && QApplicationPrivate::inPopupMode()) {
QWidget *popup = QApplication::activePopupWidget();
QWidget *popupFocusWidget = popup->focusWidget();
receiver = popupFocusWidget ? popupFocusWidget : popup;
}
if (!receiver)
receiver = focusObject();
QGuiApplication::sendSpontaneousEvent(receiver, event);
}
示例15: handleGestureEvent
void QWidgetWindow::handleGestureEvent(QNativeGestureEvent *e)
{
// copy-pasted code to find correct widget follows:
QObject *receiver = 0;
if (QApplicationPrivate::inPopupMode()) {
QWidget *popup = QApplication::activePopupWidget();
QWidget *popupFocusWidget = popup->focusWidget();
receiver = popupFocusWidget ? popupFocusWidget : popup;
}
if (!receiver)
receiver = QApplication::widgetAt(e->globalPos());
if (!receiver)
receiver = m_widget; // last resort
QApplication::sendSpontaneousEvent(receiver, e);
}