Below is my progress thus far in trying to create a test application.
I've created a simple app with just two QPlainTextEdit's. The only thing
else it does is to print out the name of the keyboard input source
associated with a QPlainTextEdit when you click into it. I'm unsure how
to translate the python code for changing the keyboard into C++ but I've
added comments to the "MainWindow::changeKeyboard" method below to show
my approach in python. Any help or suggestions would be most welcome.
Best regards,
Tim
mainwindow.h:
#ifndefMAINWINDOW_H
#defineMAINWINDOW_H
#include<QMainWindow>
#include<QPlainTextEdit>
classMainWindow:publicQMainWindow
{
Q_OBJECT
public:
MainWindow();
voidchangeKeyboard(QVariantkeyboard);
protected:
booleventFilter(QObject*obj,QEvent*event);
private:
QWidget*mainWidget;
QPlainTextEdit*textEdit1;
QPlainTextEdit*textEdit2;
};
#endif//MAINWINDOW_H mainwindow.cpp:
#include<QWidget> #include<QVBoxLayout> #include<QPlainTextEdit>
#include<QObject> #include<QEvent> #include<QDebug>
#include"mainwindow.h"MainWindow::MainWindow() { mainWidget=newQWidget;
setCentralWidget(mainWidget); QVBoxLayout*layout=newQVBoxLayout;
textEdit1=newQPlainTextEdit;
textEdit1->setProperty("keyboard",0x00000809);//British(Windows)
textEdit2=newQPlainTextEdit;
textEdit2->setProperty("keyboard",0x00010C00);//Myanmar(Windows)
layout->addWidget(textEdit1); layout->addWidget(textEdit2);
mainWidget->setLayout(layout);textEdit1->installEventFilter(this);
textEdit2->installEventFilter(this); }
boolMainWindow::eventFilter(QObject*obj,QEvent*event) {
if(obj==textEdit1||obj==textEdit2){ if(event->type()==QEvent::FocusIn){
changeKeyboard(obj->property("keyboard")); } }
returnQMainWindow::eventFilter(obj,event); }
voidMainWindow::changeKeyboard(QVariantkeyboard) {
qDebug()<<keyboard.toString(); /* The following is how I did this in
Python but I am unsure how to translate this into C++. A different
approach in C++ would be okay, but it needs to be an approach I can
translate back into Python/PyQt. from Cocoa import NSTextInputContext
//This line goes at top of page with any other import statements ic =
NSTextInputContext.currentInputContext() if not ic: ic =
NSTextInputContext.new() ic.setValue_forKey_(keyboard.toString(),
'selectedKeyboardInputSource') */ }
On 19/08/2016 16:48, timur.kris...@gmail.com wrote:
Can you create a simple example app without Python, to see if it really is Qt's
fault?
(Just create an app with Qt Creator and run it. As far as I understand, you use
QWidgets, right? If so, create an empty QWitgets project, run and see how it
goes.)
On Fri Aug 19 13:33:58 2016 GMT+0200, Timothy W. Grove wrote:
Changing the keyboard input source on OS X back and forth between
'British' and 'Myanmar-QWERTY' crashes my PyQt v5.7 application after
about three changes, usually corrupting an attached sqlite database as
well. 'Myanmar-QWERTY' is the only input source that I'm having trouble
with; all others that I've tested so far appear okay. The windows
version of the application also seems okay. My application is fairly
complex, but I'm seeing this issue even with an absolute minimal app
containing only one window. I'm not certain if the issue is with PyQt or
Qt or the input source itself, but it doesn't appear to be with python
as a Tkinter app worked okay.
Any answers would be great, but if anyone could suggest where to find a
solution that would also be helpful. This is a pretty obscure bug, but
finding a solution or work-around is important to the application I'm
developing. Thank you.
Best regards,
Timothy Grove
Test program:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtWidgets import QApplication
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
text = QTextEdit()
self.setCentralWidget(text)
if __name__ == "__main__":
app = QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest