Ejemplo n.º 1
0
 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 = QString(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 = QString(' ')
         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
Ejemplo n.º 2
0
    def setupUi(self):
        super(MainWindow, self).setupUi(self)

        self.search_box.shortcut = QShortcut(self.search_box)
        self.search_box.shortcut.setKey('Ctrl+F')

        self.output_devices_group = QActionGroup(self)
        self.input_devices_group = QActionGroup(self)
        self.alert_devices_group = QActionGroup(self)
        self.video_devices_group = QActionGroup(self)

        self.request_screen_action = QAction('Request screen', self, triggered=self._AH_RequestScreenActionTriggered)
        self.share_my_screen_action = QAction('Share my screen', self, triggered=self._AH_ShareMyScreenActionTriggered)
        self.screen_sharing_button.addAction(self.request_screen_action)
        self.screen_sharing_button.addAction(self.share_my_screen_action)

        # adjust search box height depending on theme as the value set in designer isn't suited for all themes
        search_box = self.search_box
        option = QStyleOptionFrameV2()
        search_box.initStyleOption(option)
        frame_width = search_box.style().pixelMetric(QStyle.PM_DefaultFrameWidth, option, search_box)
        if frame_width < 4:
            search_box.setMinimumHeight(20 + 2*frame_width)

        # adjust the combo boxes for themes with too much padding (like the default theme on Ubuntu 10.04)
        option = QStyleOptionComboBox()
        self.identity.initStyleOption(option)
        wide_padding = self.identity.style().subControlRect(QStyle.CC_ComboBox, option, QStyle.SC_ComboBoxEditField, self.identity).height() < 10
        self.identity.setStyleSheet("""QComboBox { padding: 0px 4px 0px 4px; }""" if wide_padding else "")
Ejemplo n.º 3
0
 def paint(self, painter, option, index):
     self.initStyleOption(option, index)
     # No idea why, but this cast is required if we want to have access to the V4 valuess
     option = QStyleOptionViewItemV4(option)
     if (index.column() == 1) and (option.state & QStyle.State_Selected):
         cboption = QStyleOptionComboBox()
         cboption.rect = option.rect
         # On OS X (with Qt4.6.0), adding State_Enabled to the flags causes the whole drawing to
         # fail (draw nothing), but it's an OS X only glitch. On Windows, it works alright.
         cboption.state |= QStyle.State_Enabled
         QApplication.style().drawComplexControl(QStyle.CC_ComboBox, cboption, painter)
         painter.setBrush(option.palette.text())
         rect = QRect(option.rect)
         rect.setLeft(rect.left()+4)
         painter.drawText(rect, Qt.AlignLeft, option.text)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
Ejemplo n.º 4
0
 def paint(self, painter, option, index):
     self.initStyleOption(option, index)
     # No idea why, but this cast is required if we want to have access to the V4 valuess
     option = QStyleOptionViewItemV4(option)
     if (index.column() == 1) and (option.state & QStyle.State_Selected):
         cboption = QStyleOptionComboBox()
         cboption.rect = option.rect
         # On OS X (with Qt4.6.0), adding State_Enabled to the flags causes the whole drawing to
         # fail (draw nothing), but it's an OS X only glitch. On Windows, it works alright.
         cboption.state |= QStyle.State_Enabled
         QApplication.style().drawComplexControl(QStyle.CC_ComboBox,
                                                 cboption, painter)
         painter.setBrush(option.palette.text())
         rect = QRect(option.rect)
         rect.setLeft(rect.left() + 4)
         painter.drawText(rect, Qt.AlignLeft, option.text)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
Ejemplo n.º 5
0
    def paintEvent(self, _):
        painter = QStylePainter(self)
        painter.setPen(self.palette().color(QPalette.Text))

        opt = QStyleOptionComboBox()
        self.initStyleOption(opt)
        painter.drawComplexControl(QStyle.CC_ComboBox, opt)

        frame = self.style().subControlRect(QStyle.CC_ComboBox, opt,
                                            QStyle.SC_ComboBoxEditField, self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.transparent)
        painter.setBrush(self.color())
        painter.drawRoundedRect(frame.adjusted(1, 1, -1, -2), 2, 2)
Ejemplo n.º 6
0
 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 = QString(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 = QString(' ')
         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
Ejemplo n.º 7
0
 def paint(self, painter, option, index):
     if index.column() is self._column:
         comboBoxOption = QStyleOptionComboBox()
         comboBoxOption.rect = option.rect
         comboBoxOption.currentText = index.data(Qt.DisplayRole).toString()
         if convert_string(comboBoxOption.currentText) == u"Default":  
             comboBoxOption.state = QStyle.State_Active
         else:  
             comboBoxOption.state = QStyle.State_Active | QStyle.State_Enabled
         comboBoxOption.frame = True
         QApplication.style().drawComplexControl(QStyle.CC_ComboBox, comboBoxOption, painter)
         QApplication.style().drawControl(QStyle.CE_ComboBoxLabel, comboBoxOption, painter)
     else:
         super(ComboboxDelegate, self).paint(painter, option, index)