I have an issue with the gui app
I am building.
The class Interface contains the menubar
, the toolbar(which does not display neither), and call the class TabWidget_
.
The class TabWidget_ contains tabs. There is only one tab at the moment (the tab "Synthèse
"). I have several groups to the table (Coordonnées, Equipe, Patrimoine, Bailleurs, Observations)
.
tab is a QtGui.QWidget()
. All the groups are in tab. And I added tab into scrollArea (scrollArea = QtGui.QScrollArea())
.
I have also looked at other posts but did not find my error.
My code is like this.
import os
import platform
import sys
from PyQt4 import QtCore, QtGui
class Interface(QtGui.QMainWindow):
def __init__(self):
super(Interface, self).__init__()
self.setWindowTitle('Compagnons Batisseur')
self.resize(1440, 900)
self.edit= QtGui.QTextEdit()
self.barre_menu()
self.centralwidget = QtGui.QLabel()
self.tab_barre=TabWidget_(self.centralwidget)
self.setCentralWidget(self.centralwidget)
self.show()
def test(self):
self.edit.setGeometry(QtCore.QRect(20, 40, 601, 501))
self.edit.setStatusTip('Input Text Here')
self.edit.setToolTip('Input Text Here')
def createAction(self,text, icon=None, shortcut=None, tip=None, slot=None):
action=QtGui.QAction(QtGui.QIcon(icon),text, self)
try:
action.setShortcut(shortcut)
action.setStatusTip(tip)
action.setToolTip(tip)
action.triggered.connect(slot)
except TypeError:
pass
return action
def addMenuItem(self, nomItem):
item=self.menuBar().addMenu(nomItem)
return item
def barre_menu(self):
#Fichier
exitAction=self.createAction("Fermer", icon="logout.png", shortcut="Ctrl+Q", tip="Fermer l'application", slot=self.close) #on va aussi reimplementer la close event handler pour que quand on appuie sur croix, la methode soit lue egalement. ce sera pratique pour enregistrer les changements
#saveAction=self.createAction("Enregistrer", icon="save.png", shortcut="Ctrl+S", tip="Enregistrer", slot=self.save)
fichier=self.addMenuItem('Fichier')
fichier.addActions([exitAction])
#Edition
cutAction=self.createAction("Couper", icon="cut.png", shortcut=QtGui.QKeySequence.Cut, tip="Couper", slot=self.edit.cut)
copyAction=self.createAction("Copier", icon="copy.png", shortcut=QtGui.QKeySequence.Copy, tip="Copier", slot=self.edit.copy)
pasteAction=self.createAction("Coller", icon="paste.png", shortcut=QtGui.QKeySequence.Paste, tip="Coller", slot=self.edit.paste)
edition=self.menuBar().addMenu('Edition')
edition.addActions([cutAction, copyAction, pasteAction])
edition=self.menuBar().addMenu('Edition')
#Aide
aide=self.menuBar().addMenu('Aide')
#Barre d'Outils, a enlever pas necessaire
toolbar = self.addToolBar('Exit')
toolbar.addAction(exitAction)
toolbar.addAction(copyAction)
toolbar.addAction(pasteAction)
toolbar.addAction(cutAction)
class TabWidget_(QtGui.QWidget):
def __init__(self, centralwidget, parent=None):
QtGui.QWidget.__init__(self)
super(TabWidget_,self).__init__(parent)
self.Onglets = QtGui.QTabWidget(centralwidget)
self.Onglets.setGeometry(QtCore.QRect(0, 0, 1400, 871))
self.Onglets.setFocusPolicy(QtCore.Qt.TabFocus)
self.Onglets.setLayoutDirection(QtCore.Qt.LeftToRight)
self.Onglets.setMovable(False)
self.Tab_Synthese()
def create_group(self,nom_tab, nom_groupe, x, y, w, h):
group=QtGui.QGroupBox(nom_tab)
group.setTitle(nom_groupe)
group.setGeometry(QtCore.QRect(x,y,w,h))
return group
def create_line(self,nom_groupe, nom_line, x, y, w, h):
line = QtGui.QLabel(nom_groupe)
line.setGeometry(QtCore.QRect(x,y,w,h))
line.setFocusPolicy(QtCore.Qt.TabFocus)
line.setObjectName(nom_line)
line.setText(nom_line)
return line
def create_line_edit(self,nom_groupe, x, y, w, h):
line_edit=QtGui.QLineEdit(nom_groupe)
line_edit.setGeometry(QtCore.QRect(x,y,w,h))
return line_edit
def Tab_Synthese(self):
scrollArea = QtGui.QScrollArea()
tab=QtGui.QWidget()
#Création de l'onglet Synthèse
#self.Onglets.addTab(tab, "Synthèsse")
#Groupe COORDONNEES
coordonnees=self.create_group(tab, "Coordonnées", 400, 20, 471, 500)
#Eléments du groupe Coordonnées
adresse=self.create_line(coordonnees, "Adresse", 10,25,150,30)
adresse_edit= self.create_line_edit(coordonnees, 170, 25, 260, 30)
code_postal = self.create_line(coordonnees, "Code Postal", 10, 60,150,30)
code_postal_edit=self.create_line_edit(coordonnees,170, 60, 60, 30)
ville=self.create_line(coordonnees, "Ville", 10,95,50,30)
ville_edit= self.create_line_edit(coordonnees, 170, 95, 135, 30)
téléphone = self.create_line(coordonnees, "Téléphone", 10, 130, 150, 30)
téléphone_edit=self.create_line_edit(coordonnees,170, 130, 100, 30)
#Groupe EQUIPE
equipe =self.create_group(tab, "Equipe", 400, 190, 471, 500)
#Eléments du groupe Equipe
anim_tech = self.create_line(equipe, "Animateur technique", 10, 25, 150, 30)
anim_tech_edit=self.create_line_edit(equipe,170, 25, 260, 30)
anim_hab = self.create_line(equipe, "Animateur habitat", 10, 60, 150, 30)
anim_hab_edit=self.create_line_edit(equipe,170, 60, 260, 30)
#Groupe PATRIMOINE
patrimoine = self.create_group(tab, "Patrimoine", 400, 290, 471, 500)
#Eléments du groupe Patrimoine
nb_immeubles = self.create_line(patrimoine, "Nombre d'immeubles", 10, 25, 150, 30)
nb_immeubles_edit=self.create_line_edit(patrimoine,170, 25, 260, 30)
nb_logements = self.create_line(patrimoine, "Nombre de logements", 10, 60, 150, 30)
anim_hab_edit=self.create_line_edit(patrimoine,170, 60, 260, 30)
#Groupe BAIL
bail = self.create_group(tab, "Bailleurs", 400, 390, 471, 500)
#Eléments du groupe Equipe
date = self.create_line(bail, "Date d'ouverture", 10, 25, 150, 30)
date_edit= self.create_line_edit(bail, 170, 25, 150, 30)
bailleur = self.create_line(bail, "Bailleurs", 10, 60, 150, 30)
bailleurs_edit= QtGui.QComboBox(bail)
bailleurs_edit.setGeometry(QtCore.QRect(170, 60, 260, 30))
bailleurs_edit.addItem("item1")
bailleurs_edit.addItem("item2")
#Groupe OBSERVATIONS
observations = self.create_group(tab, "Observations", 400, 490, 471, 500)
text=QtGui.QTextEdit(observations)
text.setGeometry(QtCore.QRect(10,25 , 420, 200))
scrollArea.setWidget(tab)
#scrollArea.setBackgroundRole(QtGui.QPalette.Dark)
scrollArea.setWidgetResizable(True)
scrollArea.setFixedHeight(800)
self.Onglets.addTab(scrollArea,"Synthèse")
Any idea ? Thanks.
Using fixed sizes is something I rarely recommend, I prefer to use the layout(
QHBoxLayout
,QVBoxLayout
,QFormLayout
,QGridLayout
) withQSpacerItem
if necessary, so modify your code to fit it as shown below:Obtaining what the following image shows:
The complete code is on the following link.