1 - La classe QLineEdit
La bibliothèque PyQt5 est doté de la classe QLineEdit qui permet de créer des champ de saisi ayant une seule ligne. QLineEdit est doté d'une collection utile de fonctions d'édition, y compris annuler et refaire, couper et coller, et glisser-déposer. C'est le widget de base de PyQt5 pour recevoir une entrée au clavier, l'entrée peut également être du texte, des nombres ou même un symbole.
Pour créer un contrôle QLineEdit, il suffit d'importer et faire une instanciation sur la classe QLineEdit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import sys from PyQt5.QtWidgets import QApplication , QWidget, QLineEdit app = QApplication(sys.argv) win = QWidget() win.setWindowTitle("Example of QLineEdit") win.setGeometry(100 , 100 , 400 , 300) # create a QLineEdit qLine = QLineEdit(win) qLine.setGeometry(50, 100 , 200 , 50) win.show() sys.exit(app.exec_()) |
2 - Appliquer un style à un champ QLineEdit
QLineEdit est doté de la méthode setStyleSheet() qui permet d'associer un style Qt Style Sheet (QSS)
Example
1 |
qLine.setStyleSheet("background: black; color: yellow; font-size:28px;") |
3 - QLineEdit selon l'approche objet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import sys from PyQt5.QtWidgets import QApplication , QWidget, QLineEdit class MyWindow(QWidget): def __init__(self , win): super().__init__() self.win = win def build(self): self.win.setWindowTitle("QLineEdit Exemple") self.win.setGeometry(100 , 100 , 500 , 300) # create a QLineEdit self.qLine = QLineEdit(self.win) self.qLine.setGeometry(50 , 50 , 250 , 35) if __name__ == '__main__': app = QApplication(sys.argv) root = QWidget() mywin = MyWindow(root) mywin.build() root.show() sys.exit(app.exec_()) |
Younes Derfoufi
CRMEF OUJDA
Acheter sur Très Facile !
-
Obtenez Microsoft 365 Famille avec Office 365 apps - 15 Mois + NORTON 360 Deluxe - PC/MAC, tablette et smartphone
€ 57,00 Acheter le produit -
Apprendre Raspberry Pi 4 - sur votre nano-ordinateur avec un projet de station
€ 29,00 Acheter le livre -
Python 3 par la pratique avec exercices corrigés
€ 37,00 Acheter le livre