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

Wilhelm wilhelm.meier at fh-kl.de
Fri Dec 19 13:29:39 CET 2014


Am 19.12.2014 um 12:37 schrieb Sze Howe Koh:
> 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? 

On Linux with Qt 5.3.2 and 5.4.0: both experience the same problem ...

Did you find a workaround?

> 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
> 


-- 
Wilhelm
w.meier at unix.net



More information about the Interest mailing list