def createItem(minimum, preferred, maximum, name): w = QtGui.QGraphicsProxyWidget() w.setWidget(QtGui.QPushButton(name)) w.setMinimumSize(minimum) w.setPreferredSize(preferred) w.setMaximumSize(maximum) w.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) return w
def __init__(self, rect, brush, embeddedWidget=None): super(RoundRectItem, self).__init__(rect) self.brush = QtGui.QBrush(brush) self.timeLine = QtCore.QTimeLine(75) self.lastVal = 0 self.opa = 1 self.proxyWidget = None self.pix = QtGui.QPixmap() # In the C++ version of this example, this class is also derived from # QObject in order to emit the activated() signal. PyQt does not # support deriving from more than one wrapped class so we just create # an explicit QObject sub-class. self.qobject = Activated() self.timeLine.valueChanged.connect(self.updateValue) if embeddedWidget: self.proxyWidget = QtGui.QGraphicsProxyWidget(self) self.proxyWidget.setFocusPolicy(QtCore.Qt.StrongFocus) self.proxyWidget.setWidget(embeddedWidget) self.proxyWidget.setGeometry(self.boundingRect().adjusted( 25, 25, -25, -25))
if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) # Text edit and button. edit = QtGui.QTextEdit() edit.setText("asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy!") button = QtGui.QPushButton() buttonProxy = QtGui.QGraphicsProxyWidget() buttonProxy.setWidget(button) editProxy = QtGui.QGraphicsProxyWidget() editProxy.setWidget(edit) box = QtGui.QGroupBox() box.setFlat(True) box.setTitle("Options") layout2 = QtGui.QVBoxLayout() box.setLayout(layout2) layout2.addWidget(QtGui.QRadioButton("Herring")) layout2.addWidget(QtGui.QRadioButton("Blue Parrot")) layout2.addWidget(QtGui.QRadioButton("Petunias")) layout2.addStretch()