3

と を使用して簡単な Qt ウィンドウ レイアウトを作成しました。ツリー ビューでアイテムを選択するQTreeViewQWebEngineView、Web エンジン ビューにコンテンツが表示されます。問題は、ツリー ビューがキーボード フォーカスを失い、Web エンジン ビューがそれを取得した場合ですQWebEngineView::setHtml(...)load(...)これにより、ツリー ビューでキーボードを使用して項目を選択する際に問題が発生します。では、ツリー ビューのフォーカスが失われるのを防ぐにはどうすればよいでしょうか。

QTextBrowserの代わりに使ってみましたQWebEngineView。この問題はありませんが、複雑な HTML ページには適していません。

4

3 に答える 3

1

Thanks to all the others who provided answers for this. After encountering this bug I was somewhat stumped, but after learning of the way setEnabled(false) affects the focus stealing from the other answers I discovered that simply disabling the webview, setting the html or reloading it, then re-enabling it circumvents the issue (at least in Qt 5.7):

I.E.

myWebView->setEnabled( false );
myWebView->setHtml( html );
myWebView->setEnabled( true );

or

myWebView->setEnabled( false );
myWebView->reload();
myWebView->setEnabled( true );

This allows you to fix the problem without needing to subclass anything as one of the other answers suggests.

于 2016-12-11T22:29:03.887 に答える