Ok inizio a capire il meccanismo.
Ho scritto questa classe che sovrascrive il metodo che gestisce i click del mouse.
codice:class WidRect(QWidget): def __init__(self, mIntMeasureId,mStrLabel=None): super().__init__() self.aIntMeasureId=mIntMeasureId self.aStrLabel=mStrLabel #self.setWidget(QLabel(mStrLabel)) def getLabel(): return self.aStrLabel; def mousePressEvent(self, QMouseEvent): if QMouseEvent.button() == Qt.LeftButton: print("Left Button Clicked on measure "+ str(self.aIntMeasureId)) elif QMouseEvent.button() == Qt.RightButton: #do what you want here print("Right Button Clicked on measure "+ str(self.aIntMeasureId))
Funziona tutto ma dovrei aggiungere del testo e/o un'immagine nel rettangolo. Come posso aggiungere un widget a un altro widget? Se provo a usare setWidget o addWidget nel costruttore mi dice che l'oggetto non possiede quel metodo.
Sbaglio il ragionamento di base? Non è possibile aggiungere un widget a un altro?
Grazie ancora dell'aiuto![]()


Rispondi quotando