How can i show the my virtual keyboard in line edit using with pyqt4
up vote
0
down vote
favorite
This is my sample code. In my actual project i used 2 line edits in different places. By using this code i need to create a virtual keyboard.So that it should display a virtual keyboard if we click on line edit.By using the same virtual keyboard i wish to enter my text in line edit.finally i created a virtual keyboard but the problem is its only applicable to first line edit,but i want to call the same keyboard to another line edit also.I am not getting the keyboard for second line edit can any one please tell me how to i display keyboard to second line edit.
import sys
from pyface.qt import QtGui, QtCore
from functools import partial
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.central_widget = QtGui.QWidget()
self.cw_layout = QtGui.QHBoxLayout()
self.central_widget.setLayout(self.cw_layout)
self.setCentralWidget(self.central_widget)
self.btn = QtGui.QPushButton("save")
self.btn.clicked.connect(self.savebtn)
self.line = LineEdit()
self.line_edit1 = LineEdit()
self.kb = KeyBoard()
self.cw_layout.addWidget(self.line)
self.cw_layout.addWidget(self.btn)
self.create_connections()
def savebtn(self):
global fileName
self.d1 = QtGui.QDialog()
self.form1 = QtGui.QFormLayout(self.d1)
self.name_file = QtGui.QLabel("File Name:")
self.line_edit1 = LineEdit()
self.d1.close()
self.saveBtn = QtGui.QPushButton("Save")
self.saveBtn.clicked.connect(self.savefile)
self.canclebtn = QtGui.QPushButton("Cancel")
self.canclebtn.clicked.connect(self.d1.close)
self.form1.addRow(self.name_file, self.line_edit1)
self.form1.addRow( self.canclebtn,self.saveBtn)
self.d1.setWindowTitle("Enter Grids")
self.d1.setGeometry(350,200,300,100)
self.d1.setWindowModality(QtCore.Qt.ApplicationModal)
self.d1.exec_()
def savefile(self):
self.d1.close()
text = self.line_edit1.text()
print "line edit text issssssssssss",text
def create_connections(self):
self.line.signal_evoke_kb.connect(self.show_kb)
self.line_edit1.signal_evoke_kb.connect(self.show_kb)
def show_kb(self):
if self.kb.isHidden():
self.kb.show()
else:
self.kb.hide()
class LineEdit(QtGui.QLineEdit):
signal_evoke_kb = QtCore.Signal()
def __init__(self):
super(LineEdit, self).__init__()
def mousePressEvent(self, QMouseEvent):
super(LineEdit, self).mousePressEvent(QMouseEvent)
self.signal_evoke_kb.emit()
class KeyBoard(QtGui.QWidget):
def __init__(self):
super(KeyBoard, self).__init__()
self.vBox = QtGui.QVBoxLayout()
self.flayout = QtGui.QHBoxLayout()
self.slayout = QtGui.QHBoxLayout()
self.tlayout = QtGui.QHBoxLayout()
self.folayout = QtGui.QHBoxLayout()
self.btnlayout = QtGui.QHBoxLayout()
custom_signal = QtCore.Signal()
for i in range(0,10):
self.accBtn = QtGui.QPushButton(str(i))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,i))
self.flayout.addWidget(self.accBtn)
for key in [ 'q','w','e','r','t','y','u','i','o','p']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.slayout.addWidget(self.accBtn)
for key in [ 'a','s','d','f','g','h','i','j','k','l']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.tlayout.addWidget(self.accBtn)
for key in [ 'z','x','c','v','b','n','m','.' , ',']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.folayout.addWidget(self.accBtn)
self.btn = QtGui.QPushButton("Backspace")
self.btn.clicked.connect(self.backspace)
self.btnlayout.addWidget(self.btn)
self.btn1 = QtGui.QPushButton("Enter")
self.btn1.clicked.connect(self.enter)
self.btnlayout.addWidget(self.btn1)
self.btn2 = QtGui.QPushButton("Close")
self.btn2.clicked.connect(self.close)
self.btnlayout.addWidget(self.btn2)
self.vBox.addLayout(self.flayout)
self.vBox.addLayout(self.slayout)
self.vBox.addLayout(self.tlayout)
self.vBox.addLayout(self.folayout)
self.vBox.addLayout(self.btnlayout)
self.setLayout(self.vBox)
self.setWindowTitle('Virtual keyboard')
def backspace(self):
self.line.backspace()
def keyBoardClicked(self,key):
pass
def enter(self):
print "enterrrrr"
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
python pyqt pyqt4
add a comment |
up vote
0
down vote
favorite
This is my sample code. In my actual project i used 2 line edits in different places. By using this code i need to create a virtual keyboard.So that it should display a virtual keyboard if we click on line edit.By using the same virtual keyboard i wish to enter my text in line edit.finally i created a virtual keyboard but the problem is its only applicable to first line edit,but i want to call the same keyboard to another line edit also.I am not getting the keyboard for second line edit can any one please tell me how to i display keyboard to second line edit.
import sys
from pyface.qt import QtGui, QtCore
from functools import partial
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.central_widget = QtGui.QWidget()
self.cw_layout = QtGui.QHBoxLayout()
self.central_widget.setLayout(self.cw_layout)
self.setCentralWidget(self.central_widget)
self.btn = QtGui.QPushButton("save")
self.btn.clicked.connect(self.savebtn)
self.line = LineEdit()
self.line_edit1 = LineEdit()
self.kb = KeyBoard()
self.cw_layout.addWidget(self.line)
self.cw_layout.addWidget(self.btn)
self.create_connections()
def savebtn(self):
global fileName
self.d1 = QtGui.QDialog()
self.form1 = QtGui.QFormLayout(self.d1)
self.name_file = QtGui.QLabel("File Name:")
self.line_edit1 = LineEdit()
self.d1.close()
self.saveBtn = QtGui.QPushButton("Save")
self.saveBtn.clicked.connect(self.savefile)
self.canclebtn = QtGui.QPushButton("Cancel")
self.canclebtn.clicked.connect(self.d1.close)
self.form1.addRow(self.name_file, self.line_edit1)
self.form1.addRow( self.canclebtn,self.saveBtn)
self.d1.setWindowTitle("Enter Grids")
self.d1.setGeometry(350,200,300,100)
self.d1.setWindowModality(QtCore.Qt.ApplicationModal)
self.d1.exec_()
def savefile(self):
self.d1.close()
text = self.line_edit1.text()
print "line edit text issssssssssss",text
def create_connections(self):
self.line.signal_evoke_kb.connect(self.show_kb)
self.line_edit1.signal_evoke_kb.connect(self.show_kb)
def show_kb(self):
if self.kb.isHidden():
self.kb.show()
else:
self.kb.hide()
class LineEdit(QtGui.QLineEdit):
signal_evoke_kb = QtCore.Signal()
def __init__(self):
super(LineEdit, self).__init__()
def mousePressEvent(self, QMouseEvent):
super(LineEdit, self).mousePressEvent(QMouseEvent)
self.signal_evoke_kb.emit()
class KeyBoard(QtGui.QWidget):
def __init__(self):
super(KeyBoard, self).__init__()
self.vBox = QtGui.QVBoxLayout()
self.flayout = QtGui.QHBoxLayout()
self.slayout = QtGui.QHBoxLayout()
self.tlayout = QtGui.QHBoxLayout()
self.folayout = QtGui.QHBoxLayout()
self.btnlayout = QtGui.QHBoxLayout()
custom_signal = QtCore.Signal()
for i in range(0,10):
self.accBtn = QtGui.QPushButton(str(i))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,i))
self.flayout.addWidget(self.accBtn)
for key in [ 'q','w','e','r','t','y','u','i','o','p']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.slayout.addWidget(self.accBtn)
for key in [ 'a','s','d','f','g','h','i','j','k','l']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.tlayout.addWidget(self.accBtn)
for key in [ 'z','x','c','v','b','n','m','.' , ',']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.folayout.addWidget(self.accBtn)
self.btn = QtGui.QPushButton("Backspace")
self.btn.clicked.connect(self.backspace)
self.btnlayout.addWidget(self.btn)
self.btn1 = QtGui.QPushButton("Enter")
self.btn1.clicked.connect(self.enter)
self.btnlayout.addWidget(self.btn1)
self.btn2 = QtGui.QPushButton("Close")
self.btn2.clicked.connect(self.close)
self.btnlayout.addWidget(self.btn2)
self.vBox.addLayout(self.flayout)
self.vBox.addLayout(self.slayout)
self.vBox.addLayout(self.tlayout)
self.vBox.addLayout(self.folayout)
self.vBox.addLayout(self.btnlayout)
self.setLayout(self.vBox)
self.setWindowTitle('Virtual keyboard')
def backspace(self):
self.line.backspace()
def keyBoardClicked(self,key):
pass
def enter(self):
print "enterrrrr"
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
python pyqt pyqt4
thq sir.now my problem is that virtual keyboard is not applicable to second line edit i.e self.line_edit1
– raghava
Nov 13 at 6:01
i wanna call same keyboard to self.line_edit1 = LineEdit() also
– raghava
Nov 13 at 6:03
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is my sample code. In my actual project i used 2 line edits in different places. By using this code i need to create a virtual keyboard.So that it should display a virtual keyboard if we click on line edit.By using the same virtual keyboard i wish to enter my text in line edit.finally i created a virtual keyboard but the problem is its only applicable to first line edit,but i want to call the same keyboard to another line edit also.I am not getting the keyboard for second line edit can any one please tell me how to i display keyboard to second line edit.
import sys
from pyface.qt import QtGui, QtCore
from functools import partial
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.central_widget = QtGui.QWidget()
self.cw_layout = QtGui.QHBoxLayout()
self.central_widget.setLayout(self.cw_layout)
self.setCentralWidget(self.central_widget)
self.btn = QtGui.QPushButton("save")
self.btn.clicked.connect(self.savebtn)
self.line = LineEdit()
self.line_edit1 = LineEdit()
self.kb = KeyBoard()
self.cw_layout.addWidget(self.line)
self.cw_layout.addWidget(self.btn)
self.create_connections()
def savebtn(self):
global fileName
self.d1 = QtGui.QDialog()
self.form1 = QtGui.QFormLayout(self.d1)
self.name_file = QtGui.QLabel("File Name:")
self.line_edit1 = LineEdit()
self.d1.close()
self.saveBtn = QtGui.QPushButton("Save")
self.saveBtn.clicked.connect(self.savefile)
self.canclebtn = QtGui.QPushButton("Cancel")
self.canclebtn.clicked.connect(self.d1.close)
self.form1.addRow(self.name_file, self.line_edit1)
self.form1.addRow( self.canclebtn,self.saveBtn)
self.d1.setWindowTitle("Enter Grids")
self.d1.setGeometry(350,200,300,100)
self.d1.setWindowModality(QtCore.Qt.ApplicationModal)
self.d1.exec_()
def savefile(self):
self.d1.close()
text = self.line_edit1.text()
print "line edit text issssssssssss",text
def create_connections(self):
self.line.signal_evoke_kb.connect(self.show_kb)
self.line_edit1.signal_evoke_kb.connect(self.show_kb)
def show_kb(self):
if self.kb.isHidden():
self.kb.show()
else:
self.kb.hide()
class LineEdit(QtGui.QLineEdit):
signal_evoke_kb = QtCore.Signal()
def __init__(self):
super(LineEdit, self).__init__()
def mousePressEvent(self, QMouseEvent):
super(LineEdit, self).mousePressEvent(QMouseEvent)
self.signal_evoke_kb.emit()
class KeyBoard(QtGui.QWidget):
def __init__(self):
super(KeyBoard, self).__init__()
self.vBox = QtGui.QVBoxLayout()
self.flayout = QtGui.QHBoxLayout()
self.slayout = QtGui.QHBoxLayout()
self.tlayout = QtGui.QHBoxLayout()
self.folayout = QtGui.QHBoxLayout()
self.btnlayout = QtGui.QHBoxLayout()
custom_signal = QtCore.Signal()
for i in range(0,10):
self.accBtn = QtGui.QPushButton(str(i))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,i))
self.flayout.addWidget(self.accBtn)
for key in [ 'q','w','e','r','t','y','u','i','o','p']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.slayout.addWidget(self.accBtn)
for key in [ 'a','s','d','f','g','h','i','j','k','l']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.tlayout.addWidget(self.accBtn)
for key in [ 'z','x','c','v','b','n','m','.' , ',']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.folayout.addWidget(self.accBtn)
self.btn = QtGui.QPushButton("Backspace")
self.btn.clicked.connect(self.backspace)
self.btnlayout.addWidget(self.btn)
self.btn1 = QtGui.QPushButton("Enter")
self.btn1.clicked.connect(self.enter)
self.btnlayout.addWidget(self.btn1)
self.btn2 = QtGui.QPushButton("Close")
self.btn2.clicked.connect(self.close)
self.btnlayout.addWidget(self.btn2)
self.vBox.addLayout(self.flayout)
self.vBox.addLayout(self.slayout)
self.vBox.addLayout(self.tlayout)
self.vBox.addLayout(self.folayout)
self.vBox.addLayout(self.btnlayout)
self.setLayout(self.vBox)
self.setWindowTitle('Virtual keyboard')
def backspace(self):
self.line.backspace()
def keyBoardClicked(self,key):
pass
def enter(self):
print "enterrrrr"
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
python pyqt pyqt4
This is my sample code. In my actual project i used 2 line edits in different places. By using this code i need to create a virtual keyboard.So that it should display a virtual keyboard if we click on line edit.By using the same virtual keyboard i wish to enter my text in line edit.finally i created a virtual keyboard but the problem is its only applicable to first line edit,but i want to call the same keyboard to another line edit also.I am not getting the keyboard for second line edit can any one please tell me how to i display keyboard to second line edit.
import sys
from pyface.qt import QtGui, QtCore
from functools import partial
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.central_widget = QtGui.QWidget()
self.cw_layout = QtGui.QHBoxLayout()
self.central_widget.setLayout(self.cw_layout)
self.setCentralWidget(self.central_widget)
self.btn = QtGui.QPushButton("save")
self.btn.clicked.connect(self.savebtn)
self.line = LineEdit()
self.line_edit1 = LineEdit()
self.kb = KeyBoard()
self.cw_layout.addWidget(self.line)
self.cw_layout.addWidget(self.btn)
self.create_connections()
def savebtn(self):
global fileName
self.d1 = QtGui.QDialog()
self.form1 = QtGui.QFormLayout(self.d1)
self.name_file = QtGui.QLabel("File Name:")
self.line_edit1 = LineEdit()
self.d1.close()
self.saveBtn = QtGui.QPushButton("Save")
self.saveBtn.clicked.connect(self.savefile)
self.canclebtn = QtGui.QPushButton("Cancel")
self.canclebtn.clicked.connect(self.d1.close)
self.form1.addRow(self.name_file, self.line_edit1)
self.form1.addRow( self.canclebtn,self.saveBtn)
self.d1.setWindowTitle("Enter Grids")
self.d1.setGeometry(350,200,300,100)
self.d1.setWindowModality(QtCore.Qt.ApplicationModal)
self.d1.exec_()
def savefile(self):
self.d1.close()
text = self.line_edit1.text()
print "line edit text issssssssssss",text
def create_connections(self):
self.line.signal_evoke_kb.connect(self.show_kb)
self.line_edit1.signal_evoke_kb.connect(self.show_kb)
def show_kb(self):
if self.kb.isHidden():
self.kb.show()
else:
self.kb.hide()
class LineEdit(QtGui.QLineEdit):
signal_evoke_kb = QtCore.Signal()
def __init__(self):
super(LineEdit, self).__init__()
def mousePressEvent(self, QMouseEvent):
super(LineEdit, self).mousePressEvent(QMouseEvent)
self.signal_evoke_kb.emit()
class KeyBoard(QtGui.QWidget):
def __init__(self):
super(KeyBoard, self).__init__()
self.vBox = QtGui.QVBoxLayout()
self.flayout = QtGui.QHBoxLayout()
self.slayout = QtGui.QHBoxLayout()
self.tlayout = QtGui.QHBoxLayout()
self.folayout = QtGui.QHBoxLayout()
self.btnlayout = QtGui.QHBoxLayout()
custom_signal = QtCore.Signal()
for i in range(0,10):
self.accBtn = QtGui.QPushButton(str(i))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,i))
self.flayout.addWidget(self.accBtn)
for key in [ 'q','w','e','r','t','y','u','i','o','p']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.slayout.addWidget(self.accBtn)
for key in [ 'a','s','d','f','g','h','i','j','k','l']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.tlayout.addWidget(self.accBtn)
for key in [ 'z','x','c','v','b','n','m','.' , ',']:
self.accBtn = QtGui.QPushButton(str(key))
self.accBtn.clicked.connect(partial(self.keyBoardClicked,key))
self.folayout.addWidget(self.accBtn)
self.btn = QtGui.QPushButton("Backspace")
self.btn.clicked.connect(self.backspace)
self.btnlayout.addWidget(self.btn)
self.btn1 = QtGui.QPushButton("Enter")
self.btn1.clicked.connect(self.enter)
self.btnlayout.addWidget(self.btn1)
self.btn2 = QtGui.QPushButton("Close")
self.btn2.clicked.connect(self.close)
self.btnlayout.addWidget(self.btn2)
self.vBox.addLayout(self.flayout)
self.vBox.addLayout(self.slayout)
self.vBox.addLayout(self.tlayout)
self.vBox.addLayout(self.folayout)
self.vBox.addLayout(self.btnlayout)
self.setLayout(self.vBox)
self.setWindowTitle('Virtual keyboard')
def backspace(self):
self.line.backspace()
def keyBoardClicked(self,key):
pass
def enter(self):
print "enterrrrr"
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
python pyqt pyqt4
python pyqt pyqt4
edited Nov 13 at 5:42
asked Nov 10 at 15:39
raghava
417
417
thq sir.now my problem is that virtual keyboard is not applicable to second line edit i.e self.line_edit1
– raghava
Nov 13 at 6:01
i wanna call same keyboard to self.line_edit1 = LineEdit() also
– raghava
Nov 13 at 6:03
add a comment |
thq sir.now my problem is that virtual keyboard is not applicable to second line edit i.e self.line_edit1
– raghava
Nov 13 at 6:01
i wanna call same keyboard to self.line_edit1 = LineEdit() also
– raghava
Nov 13 at 6:03
thq sir.now my problem is that virtual keyboard is not applicable to second line edit i.e self.line_edit1
– raghava
Nov 13 at 6:01
thq sir.now my problem is that virtual keyboard is not applicable to second line edit i.e self.line_edit1
– raghava
Nov 13 at 6:01
i wanna call same keyboard to self.line_edit1 = LineEdit() also
– raghava
Nov 13 at 6:03
i wanna call same keyboard to self.line_edit1 = LineEdit() also
– raghava
Nov 13 at 6:03
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240528%2fhow-can-i-show-the-my-virtual-keyboard-in-line-edit-using-with-pyqt4%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
thq sir.now my problem is that virtual keyboard is not applicable to second line edit i.e self.line_edit1
– raghava
Nov 13 at 6:01
i wanna call same keyboard to self.line_edit1 = LineEdit() also
– raghava
Nov 13 at 6:03