IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PyQt Python Discussion :

Passer contenu d'une QLineEdit à une QQLineEdit


Sujet :

PyQt Python

  1. #1
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut Passer contenu d'une QLineEdit à une QQLineEdit
    Bonjour,

    Je voudrais passer le contenu d'une QLineEdit dans une autre QLineEdit qui se situe dans un QTableWidget. J'utilise la fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    import sys, os
    import sqlite3
    from PyQt5.QtWidgets import (QApplication, QCheckBox, QComboBox, QDateTimeEdit,
            QDial, QDialog, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLineEdit,
            QProgressBar, QPushButton, QRadioButton, QScrollBar, QSizePolicy, QTableWidgetItem,
            QSlider, QSpinBox, QStyleFactory, QTableWidget, QTabWidget, QTextEdit,
            QVBoxLayout, QWidget, QMainWindow, QFrame, QFormLayout, QMessageBox)
    from PyQt5.QtGui import QIcon, QPixmap
    from PyQt5.QtCore import pyqtSlot, QSettings, QDateTime, Qt, QTimer, QDateTime
    from PyQt5 import QtCore, QtGui, QtWidgets, QtSql
    from PyQt5 import QtWidgets, QtGui
    from PyQt5.QtSql import QSqlDatabase
    import logging
    from logging.handlers import RotatingFileHandler
     
     
    class App(QMainWindow):
        #===============================================================================================
        def __init__(self, parent=None):
            super(App, self).__init__(parent)
            #--- Application datas ---------------------------------------------------------------------
            settings=QSettings('ini/application.ini',QSettings.IniFormat);
            global APPLICATION_NAME
            APPLICATION_NAME="DEBUG_MODE"
            self.setFont(QtGui.QFont('Courier new', 10))   
            #self.setWindowIcon(QIcon('ini/graph.ico'))
            self.setWindowTitle(APPLICATION_NAME+ " - Design By.")
     
     
            self.initUI()
        #===============================================================================================
     
        def initUI(self):
     
            #--- User Interface ------------------------------------------------------------------------
            #--- Header --------------------------------------------------------------------------------
            #Headband = QPixmap('ini/bandeau.jpg')
            #self.bandeau   = QLabel(self)
            #self.bandeau.setFixedHeight(15)
            #self.bandeau.setScaledContents(True)
            #self.bandeau.setPixmap(Headband)
     
            #--- QTabWidget creation with x tabwidget --------------------------------------------------
            self.tabwidget = QTabWidget(self)
            self.tabwidget.addTab(self.tab1(), "Tabwidget 1")
            self.tabwidget.addTab(self.tab2(), "Tabwidget 2")
            self.tabwidget.addTab(self.tab3(), "Tabwidget 3")
            self.tabwidget.addTab(self.tab4(), "Tabwidget 4")
            self.tabwidget.currentChanged.connect(self.onChange)
     
            self.setCentralWidget(QFrame())
            layout = QGridLayout()
            #layout.addWidget(self.bandeau, 0, 0)
            layout.addWidget(self.CreateToolInformationFormGroup(), 1, 0)
            layout.addWidget(self.tabwidget, 2, 0)
            #self.tabwidget.setDisabled(True)
            self.centralWidget().setLayout(layout)
     
            #--- Affichage d'un message sur la barre de status -----------------------------------------
            self.statusBar().showMessage(os.getlogin()+' is currently connected.')
     
        def onChange(self):
            print(' select self.tab1('+str(self.tabwidget.currentIndex())+')')
     
        def CreateToolInformationFormGroup(self):
            #--- QGroupBox below header ----------------------------------------------------------------
            groupBox = QGroupBox("--- QGroupBox ---")
            self.label_1 = QLabel()
            self.label_1.setText("label_1.setText")
            self.toolQRcode = QLineEdit(self)
            self.toolQRcode.textChanged.connect(self.to_upper)
            self.toolQRcode.setFixedWidth(200)
            self.toolQRcode.setMaxLength(8)
            self.toolQRcode.returnPressed.connect(self.onPressed)
            self.label_ToolInformations = QLabel()
            self.label_ToolInformations.setText("")
     
            vbox = QVBoxLayout()
            vbox.addWidget(self.label_1)
            vbox.addWidget(self.toolQRcode)
            vbox.addWidget(self.label_ToolInformations)
            #vbox.addStretch(1)
            groupBox.setLayout(vbox)
            return groupBox
     
        #--- QLineEdit in Uppercase --------------------------------------------------------------------
        def to_upper(self, txt):
            self.toolQRcode.setText(txt.upper())
     
        #--- Function after onPressed QLineEdit --------------------------------------------------------
        def onPressed(self):
            self.label_ToolInformations.setText(self.toolQRcode.text())
     
            #--- This line will be improved later with the query result ---/!\---/!\---/!\---/!\---/!\--
     
        #--- Tabwidget 1 -------------------------------------------------------------------------------             
        def tab1(self):
            groupBoxTab1 = QGroupBox("--- Tabwidget 1 ---")
     
            layout = QFormLayout()
            self.toolText = QLineEdit(self)
            layout.addRow(self.toolText)
     
            self.toolText.setText(self.toolQRcode.text())
            self.toolText.setEnabled(False)
            groupBoxTab1.setLayout(layout)
     
            return groupBoxTab1
     
     
        #--- Tabwidget 2 -------------------------------------------------------------------------------      
        def tab2(self):
            groupBoxTab2 = QGroupBox("--- Tabwidget 2 ---")
            return groupBoxTab2
     
        #--- Tabwidget 3 -------------------------------------------------------------------------------      
        def tab3(self):
            groupBoxTab3 = QGroupBox("--- Tabwidget 3 ---")
            return groupBoxTab3
     
        #--- Tabwidget 4 -------------------------------------------------------------------------------      
        def tab4(self):
            groupBoxTab4 = QGroupBox("--- Tabwidget 4 ---")
            return groupBoxTab4
     
    #--- /!\ --- DO NOT DELETE BELOW --- /!\ -----------------------------------------------------------
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        app.setStyle('Fusion')
        ex = App()
        ex.showMaximized()
        sys.exit(app.exec_())
    , mais j'ai l'erreur suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    self.toolText.setText(self.toolQRcode.text())
    AttributeError: 'App' object has no attribute 'toolQRcode'
    .

    Je ne sais pas par quel autre moyen passer la variable...

    Merci pour votre aide.

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    C'est normal, tu crées le tab avec tab1() avant de créer le QRcode avec CreateToolInformationFormGroupdeuxième().

    De toutes manières, la lineEdit du QRcode est vide au démarrage donc c'est inutile de copier son contenu.

Discussions similaires

  1. Réponses: 4
    Dernier message: 19/04/2014, 13h26
  2. Réponses: 0
    Dernier message: 23/12/2009, 12h38
  3. [DLL] Afficher le contenu d'une dll dans un Tpanel
    Par Fabs dans le forum Composants VCL
    Réponses: 4
    Dernier message: 17/08/2007, 14h30
  4. passer une chaine contenu dans une variable en nom de variable
    Par spiro13 dans le forum Général Python
    Réponses: 5
    Dernier message: 25/04/2007, 12h14
  5. [VB6] [Système] Récupérer le contenu d'une fenêtre DOS
    Par Nounours666 dans le forum VB 6 et antérieur
    Réponses: 16
    Dernier message: 18/11/2004, 16h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo