[Interest] Keyboard focus with QWidget::createWindowContainer() not working

Sze Howe Koh szehowe.koh at gmail.com
Fri Dec 19 12:37:44 CET 2014


Hi Wilhelm,

On 19 December 2014 at 17:33, Wilhelm <wilhelm.meier at fh-kl.de> wrote:
>
> Hi all,
>
> the following example code looks for the WId of a running kate-process
> and embeds the window into my own application. Thats all fine:
> rendering, resizing, mouse-events (e.g. menus of kate) are all working.
>
> The only problem ist keyboard-focus: kate doesn't get the keystrokes!
>
> I tried various thing like grabKeyboard() etc. (see below) but without
> success.
>
> Any hints!
>
> ---
>
> WId kateId = WindowSystem::findWindow(QRegularExpression("[Kk]ate"));
>
> qDebug() << "kate:" << kateId;
>
> if (kateId) {
>     QWindow* kateWindow = QWindow::fromWinId(kateId);
>     kateWindow->requestActivate();
>     qDebug() << "kate:" << kateWindow;
>     QWidget* kateWidget = QWidget::createWindowContainer(kateWindow, this);
>
>     kateWidget->setFocus();
>     kateWidget->grabKeyboard();
>
>     setCentralWidget(kateWidget);
> }

What OS did you try this on? I encountered this issue on Windows, but
it seemed to be ok for me in Linux (I embedded GEdit successfully,
with keyboard focus working as expected):
https://bugreports.qt-project.org/browse/QTBUG-40320

createWindowContainer() was designed primarily for embedding
QQuickView in a QWidget, and it hasn't been fully polished/tested for
other use cases.


Regards,
Sze-Howe



More information about the Interest mailing list