Я пытаюсь выучить PySide2 и пытаюсь смешивать обычные компоненты с некоторыми из Graphics View Framework.
Проблема в том, что 2 QGraphicsSimpleTextItems отображаются без учета требований QGraphicsGridLayout: оба одинаковыместо (поэтому полученный текст не читается).
вот мой маленький автономный код:
# coding: utf-8
from PySide2 import QtCore as core, QtWidgets as wids, QtGui as gui
import sys
class Display(wids.QMainWindow):
def __init__(self):
wids.QMainWindow.__init__(self)
self.changeGraphics()
def changeGraphics(self):
self.resize(500, 500)
#au top : un QWidget
self.central_widget = wids.QWidget(self)
self.central_layout = wids.QHBoxLayout()
self.central_widget.setLayout(self.central_layout)
self.setCentralWidget(self.central_widget)
self.label = wids.QLabel(self.central_widget)
self.label.setText('Ca marche')
self.central_layout.addWidget(self.label)
#on ajoute le nécessaire graphique
self.view = wids.QGraphicsView()
self.scene = wids.QGraphicsScene()
self.view.setScene(self.scene)
self.central_layout.addWidget(self.view)
#il faut disposer les éléments dans la scène par un QGraphicsGridLayout
##panel=conteneur général d'éléments graphiques
panel = wids.QGraphicsWidget()
self.scene.addItem(panel)
layout = wids.QGraphicsGridLayout()
panel.setLayout(layout)
#au layout, on ajoute un élément graphique
title0=wids.QGraphicsSimpleTextItem(panel)
title0.setText("JEU DE MASTERMIND")
title=wids.QGraphicsWidget(title0)
layout.addItem(title,0,0)
title1=wids.QGraphicsSimpleTextItem(panel)
title1.setText("super!")
title2=wids.QGraphicsWidget(title1)
layout.addItem(title2,1,0)
if __name__ == "__main__":
app = wids.QApplication(sys.argv)
display=Display()
display.show()
display.changeGraphics()
sys.exit(app.exec_())
thank.ll