def paint(self, painter, option, index): progressBar = None if pysideVersion == '1.2.2': progressBar = QStyleOptionProgressBarV2() progressBar.state = QStyle.State_Enabled else: progressBar = QStyleOptionProgressBar() progressBar.state = QStyle.State_Enabled progressBar.direction = QApplication.layoutDirection() progressBar.fontMetrics = QApplication.fontMetrics() progressBar.rect = option.rect progressBar.minimum = 0 progressBar.maximum = 100 progressBar.textAlignment = Qt.AlignCenter progressBar.textVisible = True dw = index.data()[0] tot = index.data()[1] if tot != 0: progressBar.progress = round(dw / tot * 100, 2) else: progressBar.progress = 0 progressBar.text = "{} MB of {} MB".format( round(dw / (1024 * 1024), 2), round(tot / (1024 * 1024), 2)) QApplication.style().drawControl(QStyle.CE_ProgressBar, progressBar, painter)
painter = QPainter() painter.begin(self) rect = QRect(5, 5, 100, self.parent.stupidSize) painter.drawRect(rect) painter.end() class MainWindow(QMainWindow): def __init__(self, parent = None): super(MainWindow, self).__init__(parent) self.setWindowTitle('Button Size Test') self.stupidSize = 3 self.dummyWidget = MyStupidWidget(self) #self.dummyWidget.addWidget(QPushButton('Knopka Huj')) self.setCentralWidget(self.dummyWidget) def sizeHint(self): return QSize(500, 400) if __name__ == '__main__': myApp = QApplication(sys.argv) mainWindow = MainWindow() mainWindow.show() sizeFont = myApp.fontMetrics().height() sizeMargin = myApp.style().pixelMetric(QStyle.PM_ButtonMargin) print 'sizeFont: {0}, sizeMargin: {1}'.format(sizeFont, sizeMargin) mainWindow.stupidSize = sizeFont + sizeMargin mainWindow.dummyWidget.update() myApp.exec_() sys.exit(0)