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 :

Probléme de multi fenétre


Sujet :

PyQt Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 33
    Points : 14
    Points
    14
    Par défaut Probléme de multi fenétre
    salut tout le monde j'ai un problème dans manipulation des fenêtre dans qt
    J'ai deux interface un main Windows et l'autre qdialog
    lorsque je Click un buttons dans main Windows pour ouvrir Qdialog çà marche mes les buttons ne fonction pas

  2. #2
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 33
    Points : 14
    Points
    14
    Par défaut
    Le problem c'est que j'ai ouvrir l'interface (View )mais je veut ouvrir le controlleur voila ma code

    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
    from PyQt4 import QtCore, QtGui
    from PyQt4.uic.properties import QtCore
     
    from Interfaces.Categorie import MyTableModel
    from Model.categorie import Category
    from Metier.Mcateg import Mcategorie
    from Interfaces.Categorie import Ui_Categorie
     
    class cat(QtGui.QDialog):
     
     
        def __init__(self):
            QtGui.QApplication.__init__(self)
            self.ui = Ui_Categorie()
            self.ui.setupUi(self)
            self.load_table_vw()
            self.ui.AddBtn.clicked.connect(self.add)
            self.ui.btnferm.clicked.connect(self.close)
            self.ui.tableView.doubleClicked.connect(self.delet_fom_tableview)
     
        def add(self):
            name = str(self.ui.TxtNom.text())
            Metcat = Mcategorie()
            modcat=Category()
            modcat.setName(name)
            Metcat.save_to_db(modcat)
            tt = MyTableModel
            get_table_data = tt(Metcat.load_from_db(), self.ui.header)
            self.ui.tableView.setModel(get_table_data)
     
     
     
        def delet_fom_tableview(self, qmodelindex):
            msgBox = QtGui.QMessageBox()
            msgBox.setWindowTitle("Confirmation de suppression du produit")
            msgBox.setText("Voulez-vous vraiment supprimer ce produit ?")
            msgBox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
            ret = msgBox.exec_()
            if ret == QtGui.QMessageBox.Ok:
                i= qmodelindex.row()
                j = qmodelindex.column()
                name = qmodelindex.sibling(i, 1).data(QtCore.Qt.DisplayRole).toString()
                print name
                Metcat = Mcategorie()
                modcat = Category()
                #modcat.setName(nom)
                Metcat.delete_from(Metcat)
     
            elif ret == QtGui.QMessageBox.Cancel:
                msgBox.Close
     
        def load_table_vw(self):
            Metcat = Mcategorie()
            lon = len(Metcat.load_from_db())
            if(lon == 0):
                msgBox = QtGui.QMessageBox()
                msg =("Aucune donnee disponible")
                msg = msg.decode("utf-8")
                msgBox.setText(msg)
                msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
                msgBox.exec_()
            else :
                tt = MyTableModel
                get_table_data = tt(Metcat.load_from_db(),self.ui.header)
                self.ui.tableView.setModel(get_table_data)
     
        def execcatego(self):
            dialog = QtGui.QDialog()
            lg = Ui_Categorie()
            lg.setupUi(dialog)
            return dialog.exec_()
     
    if __name__ == '__main__':
        import sys
        app = QtGui.QApplication(sys.argv)
        window = cat()
        window.show()
        sys.exit(app.exec_())
    que ce que je doit changer dans cette fonction pour que boutton ouvrir le controlleur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
      def execcatego(self):
            dialog = QtGui.QDialog()
            lg = Ui_Categorie()
            lg.setupUi(dialog)
            return dialog.exec_()

  3. #3
    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,

    Où est appelée cette fonction execcatego ?

    Il y d'autres choses:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    from PyQt4 import QtCore, QtGui
    from PyQt4.uic.properties import QtCore
    Le deuxième import de QtCore écrase le premier et, pour info, dans PyQt4.uic.properties QtCore = None

    Dans la fonction, remplace dialog.exec_() par lg.exec_()

    Après, on verra.

  4. #4
    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
    J'ai oublié ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    class cat(QtGui.QDialog):
        def __init__(self):
            QtGui.QApplication.__init__(self)
    Tu ne peux pas déclarer deux QApplication et d'après ton code, la classe cat est la main window et non pas une boîte de dialogue. Tu devrais donc avoir plutôt ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    class Cat(QtGui.QMainWindow):
        def __init__():
            super().__init__()
            self.ui = Ui_Categorie(self)
    ou encore:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    class Cat(object):
        def __init__():
            app = QtGui.QMainWindow()
            self.ui = Ui_Categorie(app)
    Note, au passage, l'élégante majuscule au nom de la classe.

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 33
    Points : 14
    Points
    14
    Par défaut
    Mais cat n'est pas un mainwindows lors de sa creation j'ai chosie Qdialogue

  6. #6
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 33
    Points : 14
    Points
    14
    Par défaut
    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
    # -*- coding: utf-8 -*-
     
    # Form implementation generated from reading ui file 'Categorie.ui'
    #
    # Created by: PyQt4 UI code generator 4.11.4
    #
    # WARNING! All changes made in this file will be lost!
     
    from PyQt4 import QtCore, QtGui
    import operator
    from PyQt4.QtCore import *
    from PyQt4.QtGui import QFont
     
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        def _fromUtf8(s):
            return s
     
    try:
        _encoding = QtGui.QApplication.UnicodeUTF8
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig, _encoding)
    except AttributeError:
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig)
     
    class Ui_Categorie(object):
        def setupUi(self, Categorie):
            Categorie.setObjectName(_fromUtf8("Categorie"))
            Categorie.resize(565, 336)
            Categorie.setMinimumSize(QtCore.QSize(565, 336))
            Categorie.setMaximumSize(QtCore.QSize(565, 336))
            self.header=["ID","NOM CATEGORIE"]
            self.label_2 = QtGui.QLabel(Categorie)
            self.label_2.setGeometry(QtCore.QRect(290, 120, 68, 17))
            self.label_2.setObjectName(_fromUtf8("label_2"))
            self.TxtNom = QtGui.QLineEdit(Categorie)
            self.TxtNom.setGeometry(QtCore.QRect(360, 120, 151, 27))
            self.TxtNom.setObjectName(_fromUtf8("TxtNom"))
            self.tableView = QtGui.QTableView(Categorie)
            self.tableView.setGeometry(QtCore.QRect(30, 110, 231, 141))
            self.tableView.setObjectName(_fromUtf8("tableView"))
            self.btnferm = QtGui.QPushButton(Categorie)
            self.btnferm.setGeometry(QtCore.QRect(250, 290, 99, 27))
            self.btnferm.setObjectName(_fromUtf8("btnferm"))
            self.UpBtn = QtGui.QPushButton(Categorie)
            self.UpBtn.setGeometry(QtCore.QRect(410, 210, 99, 27))
            self.UpBtn.setObjectName(_fromUtf8("UpBtn"))
            self.AddBtn = QtGui.QPushButton(Categorie)
            self.AddBtn.setGeometry(QtCore.QRect(290, 210, 99, 27))
            self.AddBtn.setObjectName(_fromUtf8("AddBtn"))
            self.label = QtGui.QLabel(Categorie)
            self.label.setGeometry(QtCore.QRect(227, 30, 111, 31))
            font = QtGui.QFont()
            font.setPointSize(16)
            self.label.setFont(font)
            self.label.setObjectName(_fromUtf8("label"))
     
            self.retranslateUi(Categorie)
            QtCore.QMetaObject.connectSlotsByName(Categorie)
            self.tableView.setShowGrid(False)
            ######
            vh = self.tableView.verticalHeader()
            vh.setVisible(False)
            # set the font
            font = QFont("Courier New", 10)
            self.tableView.setFont(font)
     
            # set horizontal header properties
            hh = self.tableView.horizontalHeader()
            hh.setStretchLastSection(True)
     
            # enable sorting
            self.tableView.setSortingEnabled(True)
     
     
     
        def retranslateUi(self, Categorie):
            Categorie.setWindowTitle(_translate("Categorie", "Categorie", None))
            self.label_2.setText(_translate("Categorie", "Nom", None))
            self.btnferm.setText(_translate("Categorie", "Fermer", None))
            self.UpBtn.setText(_translate("Categorie", "Modifier", None))
            self.AddBtn.setText(_translate("Categorie", "Ajouter", None))
            self.label.setText(_translate("Categorie", "G.Categorie", None))
     
     
    class MyTableModel(QAbstractTableModel):
        def __init__(self, datain, headerdata , parent=None, *args):
            QAbstractTableModel.__init__(self, parent, *args)
            self.arraydata = datain
            self.headerdata = headerdata
     
        def setData(self, index, value, role=QtCore.Qt.DisplayRole):
            print "setData", index.row(), index.column(), value
     
        def rowCount(self, parent):
            return len(self.arraydata)
     
        def columnCount(self, parent):
            return len(self.arraydata[0])
     
        def data(self, index, role):
            if not index.isValid():
                return QVariant()
            elif role != Qt.DisplayRole:
                return QVariant()
            return QVariant(self.arraydata[index.row()][index.column()])
     
        def headerData(self, col, orientation, role):
            if orientation == Qt.Horizontal and role == Qt.DisplayRole:
                return QVariant(self.headerdata[col])
            return QVariant()
     
        def sort(self, Ncol, order):
            """Sort table by given column number.
            """
            self.emit(SIGNAL("layoutAboutToBeChanged()"))
            self.arraydata = sorted(self.arraydata, key=operator.itemgetter(Ncol))
            if order == Qt.DescendingOrder:
                self.arraydata.reverse()
            self.emit(SIGNAL("layoutChanged()"))
    Voila le code L'interface cat
    tu peut m'explique comment faire svp exactement je suis en train d'utiliser l'architecture MVC


    Merci Beaucoup

  7. #7
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 33
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par VinsS Voir le message
    Salut,

    Où est appelée cette fonction execcatego ?

    Il y d'autres choses:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    from PyQt4 import QtCore, QtGui
    from PyQt4.uic.properties import QtCore
    Le deuxième import de QtCore écrase le premier et, pour info, dans PyQt4.uic.properties QtCore = None

    Dans la fonction, remplace dialog.exec_() par lg.exec_()

    Après, on verra.
    Merci Beacoup pour la suggestion main le problem que ici dans cette fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    def execcatego(self):
            dialog = QtGui.QDialog()
            lg = Ui_Categorie()
            lg.setupUi(dialog)
            return dialog.exec_()
    je fait l'appel de ui_categorie qui va afficher seullement l'interface mais sans fonctionalité que ce que je doit appele dans cette fonction pour que conrolleur qui va afficher interfece c'est ca la problem

  8. #8
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 33
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par Dr.root Voir le message
    Le problem c'est que j'ai ouvrir l'interface (View )mais je veut ouvrir le controlleur voila ma code

    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
    from PyQt4 import QtCore, QtGui
    from PyQt4.uic.properties import QtCore
     
    from Interfaces.Categorie import MyTableModel
    from Model.categorie import Category
    from Metier.Mcateg import Mcategorie
    from Interfaces.Categorie import Ui_Categorie
     
    class cat(QtGui.QDialog):
     
     
        def __init__(self):
            QtGui.QApplication.__init__(self)
            self.ui = Ui_Categorie()
            self.ui.setupUi(self)
            self.load_table_vw()
            self.ui.AddBtn.clicked.connect(self.add)
            self.ui.btnferm.clicked.connect(self.close)
            self.ui.tableView.doubleClicked.connect(self.delet_fom_tableview)
     
        def add(self):
            name = str(self.ui.TxtNom.text())
            Metcat = Mcategorie()
            modcat=Category()
            modcat.setName(name)
            Metcat.save_to_db(modcat)
            tt = MyTableModel
            get_table_data = tt(Metcat.load_from_db(), self.ui.header)
            self.ui.tableView.setModel(get_table_data)
     
     
     
        def delet_fom_tableview(self, qmodelindex):
            msgBox = QtGui.QMessageBox()
            msgBox.setWindowTitle("Confirmation de suppression du produit")
            msgBox.setText("Voulez-vous vraiment supprimer ce produit ?")
            msgBox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
            ret = msgBox.exec_()
            if ret == QtGui.QMessageBox.Ok:
                i= qmodelindex.row()
                j = qmodelindex.column()
                name = qmodelindex.sibling(i, 1).data(QtCore.Qt.DisplayRole).toString()
                print name
                Metcat = Mcategorie()
                modcat = Category()
                #modcat.setName(nom)
                Metcat.delete_from(Metcat)
     
            elif ret == QtGui.QMessageBox.Cancel:
                msgBox.Close
     
        def load_table_vw(self):
            Metcat = Mcategorie()
            lon = len(Metcat.load_from_db())
            if(lon == 0):
                msgBox = QtGui.QMessageBox()
                msg =("Aucune donnee disponible")
                msg = msg.decode("utf-8")
                msgBox.setText(msg)
                msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
                msgBox.exec_()
            else :
                tt = MyTableModel
                get_table_data = tt(Metcat.load_from_db(),self.ui.header)
                self.ui.tableView.setModel(get_table_data)
     
        def execcatego(self):
            dialog = QtGui.QDialog()
            lg = Ui_Categorie()
            lg.setupUi(dialog)
            return dialog.exec_()
     
    if __name__ == '__main__':
        import sys
        app = QtGui.QApplication(sys.argv)
        window = cat()
        window.show()
        sys.exit(app.exec_())
    que ce que je doit changer dans cette fonction pour que boutton ouvrir le controlleur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
      def execcatego(self):
            dialog = QtGui.QDialog()
            lg = Ui_Categorie()
            lg.setupUi(dialog)
            return dialog.exec_()
    j'ai essayer de changer dialog par self et ca marche est ce que c'est correct ? je suis nouveau python je sais pas si syntaxe est correct ou non

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     def execcatego(self):
            dialog = QtGui.QDialog()
            lg = Ui_Categorie()
            lg.setupUi(dialog)
            return self.exec_()

Discussions similaires

  1. [QtGui] Problème de multi-fenêtre
    Par Mizugola dans le forum PyQt
    Réponses: 10
    Dernier message: 08/10/2013, 01h01
  2. [WD17] Problème de focus Appli multi-fenêtre
    Par Jérôme .G dans le forum WinDev
    Réponses: 12
    Dernier message: 11/09/2013, 15h41
  3. Réponses: 0
    Dernier message: 05/09/2011, 15h16
  4. Problème d'affichage: fenêtres (frames) vides!
    Par NdmaX dans le forum Agents de placement/Fenêtres
    Réponses: 6
    Dernier message: 12/07/2005, 21h23
  5. [Javascript] Problème avec une fenêtre popup.
    Par mika0102 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 18/05/2005, 10h50

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