本文整理汇总了C++中QWidget::focusPolicy方法的典型用法代码示例。如果您正苦于以下问题:C++ QWidget::focusPolicy方法的具体用法?C++ QWidget::focusPolicy怎么用?C++ QWidget::focusPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWidget
的用法示例。
在下文中一共展示了QWidget::focusPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void K3DockWidgetPrivate::slotFocusEmbeddedWidget(QWidget* w)
{
if (w) {
QWidget* embeddedWdg = ((K3DockWidget*)w)->getWidget();
if (embeddedWdg && ((embeddedWdg->focusPolicy() == Qt::ClickFocus) || (embeddedWdg->focusPolicy() == Qt::StrongFocus))) {
embeddedWdg->setFocus();
}
}
}
示例2: eventFilter
bool MouseWheelFocusEventFilter::eventFilter(QObject* object, QEvent* event)
{
QWidget* parent = qobject_cast<QWidget*>(object);
switch (event->type())
{
case QEvent::FocusIn:
parent->setFocusPolicy(Qt::WheelFocus);
event->accept();
return false;
case QEvent::FocusOut:
parent->setFocusPolicy(Qt::StrongFocus);
event->accept();
return false;
case QEvent::Wheel:
if (parent->focusPolicy() == Qt::WheelFocus)
{
event->accept();
return false;
}
else
{
event->ignore();
return true;
}
default:
return QObject::eventFilter(object, event);
}
}
示例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)
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: _q_fixFocus
void QGroupBoxPrivate::_q_fixFocus(Qt::FocusReason reason)
{
Q_Q(QGroupBox);
QWidget *fw = q->focusWidget();
if (!fw || fw == q) {
QWidget * best = 0;
QWidget * candidate = 0;
QWidget * w = q;
while ((w = w->nextInFocusChain()) != q) {
if (q->isAncestorOf(w) && (w->focusPolicy() & Qt::TabFocus) == Qt::TabFocus && w->isVisibleTo(q)) {
if (!best && qobject_cast<QRadioButton*>(w) && ((QRadioButton*)w)->isChecked())
// we prefer a checked radio button or a widget that
// already has focus, if there is one
best = w;
else if (!candidate)
// but we'll accept anything that takes focus
candidate = w;
}
}
if (best)
fw = best;
else if (candidate)
fw = candidate;
}
if (fw)
fw->setFocus(reason);
}
示例5: fixFocus
void QGroupBox::fixFocus()
{
QFocusData * fd = focusData();
QWidget * orig = fd->home();
QWidget * best = 0;
QWidget * candidate = 0;
QWidget * w = orig;
do {
QWidget * p = w;
while( p && p != this && !p->isTopLevel() )
p = p->parentWidget();
if ( p == this && ( w->focusPolicy() & TabFocus ) == TabFocus
&& w->isVisibleTo(this) ) {
if ( w->hasFocus()
#ifndef QT_NO_RADIOBUTTON
|| ( !best && ::qt_cast<QRadioButton*>(w)
&& ((QRadioButton*)w)->isChecked() )
#endif
)
// we prefer a checked radio button or a widget that
// already has focus, if there is one
best = w;
else if ( !candidate )
// but we'll accept anything that takes focus
candidate = w;
}
w = fd->next();
} while( w != orig );
if ( best )
best->setFocus();
else if ( candidate )
candidate->setFocus();
}
示例6: event
/*!\reimp
*/
bool QLabel::event(QEvent *e)
{
Q_D(QLabel);
QEvent::Type type = e->type();
#ifndef QT_NO_SHORTCUT
if (type == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
if (se->shortcutId() == d->shortcutId) {
QWidget * w = d->buddy;
QAbstractButton *button = qobject_cast<QAbstractButton *>(w);
if (w->focusPolicy() != Qt::NoFocus)
w->setFocus(Qt::ShortcutFocusReason);
if (button && !se->isAmbiguous())
button->animateClick();
else
window()->setAttribute(Qt::WA_KeyboardFocusChange);
return true;
}
} else
#endif
if (type == QEvent::Resize) {
if (d->control)
d->textLayoutDirty = true;
} else if (e->type() == QEvent::StyleChange
#ifdef Q_WS_MAC
|| e->type() == QEvent::MacSizeChange
#endif
) {
d->setLayoutItemMargins(QStyle::SE_LabelLayoutItem);
d->updateLabel();
}
return QFrame::event(e);
}
示例7: qwtSetTabOrder
static void qwtSetTabOrder(
QWidget *first, QWidget *second, bool withChildren )
{
QList<QWidget *> tabChain;
tabChain += first;
tabChain += second;
if ( withChildren )
{
QList<QWidget *> children = second->findChildren<QWidget *>();
QWidget *w = second->nextInFocusChain();
while ( children.contains( w ) )
{
children.removeAll( w );
tabChain += w;
w = w->nextInFocusChain();
}
}
for ( int i = 0; i < tabChain.size() - 1; i++ )
{
QWidget *from = tabChain[i];
QWidget *to = tabChain[i+1];
const Qt::FocusPolicy policy1 = from->focusPolicy();
const Qt::FocusPolicy policy2 = to->focusPolicy();
QWidget *proxy1 = from->focusProxy();
QWidget *proxy2 = to->focusProxy();
from->setFocusPolicy( Qt::TabFocus );
from->setFocusProxy( NULL);
to->setFocusPolicy( Qt::TabFocus );
to->setFocusProxy( NULL);
QWidget::setTabOrder( from, to );
from->setFocusPolicy( policy1 );
from->setFocusProxy( proxy1);
to->setFocusPolicy( policy2 );
to->setFocusProxy( proxy2 );
}
}
示例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);
}
QWidget *fw = parent ? parent->window()->focusWidget() : 0;
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 (fw && (prev && prev->isAncestorOf(fw))) { // focus was on old page
// 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
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: updateTabOrder
void QwtPlot::updateTabOrder()
{
// Depending on the position of the legend the
// tab order will be changed that the canvas is
// next to the last legend item, or directly before
// the first one. The following code seems much too
// complicated but is there a better implementation ?
if ( d_canvas->focusPolicy() == QWidget::NoFocus || focusData() == NULL )
return;
// move the cursor to the canvas
for ( int i = 0; i < focusData()->count(); i++ )
{
if ( focusData()->next() == d_canvas )
break;
}
const bool canvasFirst = d_layout->legendPosition() == QwtPlot::Bottom ||
d_layout->legendPosition() == QwtPlot::Right;
for ( int j = 0; j < focusData()->count(); j++ )
{
QWidget *w = canvasFirst ? focusData()->next() : focusData()->prev();
if ( w->focusPolicy() != QWidget::NoFocus
&& w->parent() && w->parent() == d_legend->contentsWidget() )
{
if ( canvasFirst )
{
do // go back to last non legend item
{
w = focusData()->prev(); // before the first legend item
} while ( w->focusPolicy() == QWidget::NoFocus );
}
if ( w != d_canvas )
setTabOrder(w, d_canvas);
break;
}
}
}
示例10: updateTabOrder
void QwtPlot::updateTabOrder()
{
if ( d_data->canvas->focusPolicy() == Qt::NoFocus )
return;
if ( d_data->legend.isNull()
|| d_data->layout->legendPosition() == ExternalLegend
|| d_data->legend->legendItems().count() == 0 )
{
return;
}
// Depending on the position of the legend the
// tab order will be changed that the canvas is
// next to the last legend item, or before
// the first one.
const bool canvasFirst =
d_data->layout->legendPosition() == QwtPlot::BottomLegend ||
d_data->layout->legendPosition() == QwtPlot::RightLegend;
QWidget *previous = NULL;
QWidget *w = d_data->canvas;
while ( ( w = w->nextInFocusChain() ) != d_data->canvas )
{
bool isLegendItem = false;
if ( w->focusPolicy() != Qt::NoFocus
&& w->parent() && w->parent() == d_data->legend->contentsWidget() )
{
isLegendItem = true;
}
if ( canvasFirst )
{
if ( isLegendItem )
break;
previous = w;
}
else
{
if ( isLegendItem )
previous = w;
else
{
if ( previous )
break;
}
}
}
if ( previous && previous != d_data->canvas )
setTabOrder( previous, d_data->canvas );
}
示例11: getNativeObject
/*
* Returns whether the widget handles wheel scrolling.
*/
JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_handlesWheelScrolling
(JNIEnv *env, jobject obj)
{
jboolean handles = JNI_FALSE;
QWidget *cb = (QWidget *) getNativeObject( env, obj );
if( cb )
if( cb->focusPolicy() & Qt::WheelFocus )
handles = JNI_TRUE;
return handles;
}
示例12: focusNextPrevChild
bool KviMainWindow::focusNextPrevChild(bool next)
{
QWidget * w = focusWidget();
if(w)
{
if(w->focusPolicy() == Qt::StrongFocus)return false;
if(w->parent())
{
QVariant v = w->parent()->property("KviProperty_ChildFocusOwner");
if(v.isValid())return false; // Do NOT change the focus widget!
}
}
return KviTalMainWindow::focusNextPrevChild(next);
}
示例13: focusNextPrevChild
bool KviWindow::focusNextPrevChild(bool bNext)
{
QWidget * pWidget = focusWidget();
if(pWidget)
{
if(pWidget->focusPolicy() == Qt::StrongFocus)
return false;
if(pWidget->parent())
{
if(pWidget->parent()->metaObject()->indexOfProperty("KviProperty_ChildFocusOwner") == -1)
return false; // Do NOT change the focus widget!
}
}
return QWidget::focusNextPrevChild(bNext);
}
示例14: addWidgetTree
void KMdiFocusList::addWidgetTree( QWidget* w )
{
//this method should never be called twice on the same hierarchy
m_list.insert( w, w->focusPolicy() );
w->setFocusPolicy( QWidget::ClickFocus );
kdDebug( 760 ) << "KMdiFocusList::addWidgetTree: adding toplevel" << endl;
connect( w, SIGNAL( destroyed( QObject * ) ), this, SLOT( objectHasBeenDestroyed( QObject* ) ) );
QObjectList *l = w->queryList( "QWidget" );
QObjectListIt it( *l );
QObject *obj;
while ( ( obj = it.current() ) != 0 )
{
QWidget * wid = ( QWidget* ) obj;
m_list.insert( wid, wid->focusPolicy() );
wid->setFocusPolicy( QWidget::ClickFocus );
kdDebug( 760 ) << "KMdiFocusList::addWidgetTree: adding widget" << endl;
connect( wid, SIGNAL( destroyed( QObject * ) ), this, SLOT( objectHasBeenDestroyed( QObject* ) ) );
++it;
}
delete l;
}
示例15: while
QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw)
{
QWidget *tlw = m_widget;
QWidget *w = tlw->nextInFocusChain();
QWidget *last = tlw;
uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
while (w != tlw)
{
if (((w->focusPolicy() & focus_flag) == focus_flag)
&& w->isVisibleTo(m_widget) && w->isEnabled())
{
last = w;
if (fw == FirstFocusWidget)
break;
}
w = w->nextInFocusChain();
}
return last;
}