-2
I have an app that contains a Qlineedit that when active the user has the option to press the "F10" key and thus open another window.
But I’d like to block that Qlineedit for editing, leaving only available the "F10"
With the property inputMask can do that?
from sys import argv, exit
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLineEdit, QVBoxLayout, QWidget, QShortcut, QLabel
class Tela_1(QWidget):
def __init__(self):
super(Tela_1, self).__init__()
self.setWindowTitle("Tela 1 - TESTE")
self.setGeometry(50, 50, 400, 400)
# ADD WIDGETS
self.lineEdit = QLineEdit()
# ADD LAYOUT
mainLayout = QVBoxLayout()
mainLayout.addWidget(self.lineEdit)
self.setLayout(mainLayout)
# AO PRESSIONAR A TECLA "F10" CONECTAR COM A FUNÇÃO "abrir_janela2"
QShortcut(Qt.Key_F10, self.lineEdit, self.abrir_janela2, context=Qt.WidgetShortcut)
def abrir_janela2(self):
self.janela2 = Tela_2()
self.janela2.show()
class Tela_2(QWidget):
def __init__(self):
super(Tela_2, self).__init__()
self.setWindowTitle("Tela 2 - TESTE")
self.setGeometry(50, 50, 300, 300)
self.label = QLabel()
mainLayout = QVBoxLayout()
mainLayout.addWidget(self.label)
self.setLayout(mainLayout)
self.label.setText("TELA 2")
app = QApplication(argv)
w = Tela_1()
w.show()
exit(app.exec_())
It worked, thank you very much, I thought setReadOnly did not understand that Qlineedit was active when clicked.
– Rafael Pederiva