def paintEvent(self, event): """Reimplemented.""" painter = QStylePainter(self) option = QStyleOptionComboBox() self.initStyleOption(option) painter.drawComplexControl(QStyle.CC_ComboBox, option) # draw the icon and text checked = self.checkedIndices() if checked: items = [self.itemText(i) for i in checked] option.currentText = self.__separator.join(items) else: option.currentText = self.__placeholderText option.palette.setCurrentColorGroup(QPalette.Disabled) option.currentIcon = QIcon() painter.drawControl(QStyle.CE_ComboBoxLabel, option)
def paintEvent(self, e): painter = QStylePainter(self) painter.setPen(self.palette().color(QPalette.Text)) opt = QStyleOptionComboBox() self.initStyleOption(opt) count = self.model().checkedCount() if count == 0: opt.currentText = self.emptyCheckText elif count == 3: opt.currentText = self.model().singleCheckText else: opt.currentText = self.fullCheckText painter.drawComplexControl(QStyle.CC_ComboBox, opt) painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
def paintEvent(self, event): style = QApplication.style() opt = QStyleOptionComboBox() opt.rect = self.rect() self.initStyleOption(opt) painter = QPainter(self) painter.save() style.drawComplexControl(QStyle.CC_ComboBox, opt, painter) opt.currentText = self._encoder_path() style.drawControl(QStyle.CE_ComboBoxLabel, opt, painter) painter.restore()
def paint(self, painter, option, index): value = index.data() if index.column() == self.column: if option.state: opt = QStyleOptionComboBox() opt.currentText = str(value) opt.rect = option.rect QApplication.style().drawControl(QStyle.CE_ComboBoxLabel, opt, painter) else: QAbstractItemDelegate.paint(self, painter, option, index)
def getMinimumWidth(self, items=None): fm = QFontMetrics(self.font()) opt = QStyleOptionComboBox() style = self.style() mw = self.maxWidth if items is not None: for str in items: opt.currentText = str sz = QSize(fm.width(opt.currentText), fm.height()) mw = max( mw, style.sizeFromContents(QStyle.CT_ComboBox, opt, sz, self).width()) elif mw == 0 and self.count() > 0: for i in range(0, self.count()): opt.currentText = self.itemText(i) sz = QSize(fm.width(opt.currentText), fm.height()) mw = max( mw, style.sizeFromContents(QStyle.CT_ComboBox, opt, sz, self).width()) elif mw == 0: opt.currentText = ' ' sz = QSize(fm.width(opt.currentText), fm.height()) mw = max( mw, style.sizeFromContents(QStyle.CT_ComboBox, opt, sz, self).width()) self.maxWidth = mw return mw
def paintEvent(self, event): painter = QStylePainter(self) opt = QStyleOptionComboBox() self.initStyleOption(opt) selected = [] for index in range(self.__model.rowCount()): item = self.__model.item(index) if item.checkState() == Qt.Checked: selected.append(item.text()) opt.currentText = " | ".join(selected) painter.drawComplexControl(QStyle.CC_ComboBox, opt) painter.drawControl(QStyle.CE_ComboBoxLabel, opt)