0

そうするとthis->setFocusPolicy(Qt::WheelFocus);、ウィジェットの上でマウスホイールを押すと、フォーカスが移動します。ポインターが同じウィジェット内にある場合this->setFocusPolicy(Qt::ClickFocus);でも、マウスホイールを使用すると、フォーカスが失われます。では、どうすればクリックに焦点を合わせることができますが、それをマウスホイールに留めておくことができますか?

さらに調査すると、mouseWheelEventは常にフォーカスイベントの後に処理されます。したがって、これがマウスホイールによるものかどうかを記憶するために変数を設定しようとしても、機能しません。さらに、FocusReasonに示されている理由は、ホイールまたはクリックの場合のマウスであるため、どちらも役に立ちません。

4

2 に答える 2

0

列挙型Qt::FocusPolicy

This enum type defines the various policies a widget can have with respect to acquiring keyboard focus.
Constant            Value           Description
Qt::TabFocus        0x1             the widget accepts focus by tabbing.
Qt::ClickFocus      0x2             the widget accepts focus by clicking.
Qt::StrongFocus     TabFocus | 
                    ClickFocus | 
                    0x8     the widget accepts focus by both tabbing and clicking. On Mac OS X this will also be indicate that the widget accepts tab focus when in 'Text/List focus mode'.
Qt::WheelFocus      StrongFocus | 
                    0x4             like Qt::StrongFocus plus the widget accepts focus by using the mouse wheel.
Qt::NoFocus         0               the widget does not accept focus.

Qt::WheelFocusはで構成さStrongFocusれてClickFocusいるので、WheelFocusを設定して以前のすべてを取得する必要があります。

于 2012-12-28T06:58:02.810 に答える
0

以下はトリックを行います:

Foo::Foo(){
    this->setFocusPolicy(Qt::WheelFocus);
}

void Foo::focusInEvent( QFocusEvent *event ){
    if (!(QApplication::mouseButtons() & Qt::LeftButton)){
        this->clearFocus();
    }
}
于 2012-12-28T16:51:29.573 に答える