当前位置: 首页>>代码示例>>Python>>正文


Python QPushButton.setStyleSheet方法代码示例

本文整理汇总了Python中PyQt4.Qt.QPushButton.setStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:Python QPushButton.setStyleSheet方法的具体用法?Python QPushButton.setStyleSheet怎么用?Python QPushButton.setStyleSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.Qt.QPushButton的用法示例。


在下文中一共展示了QPushButton.setStyleSheet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _getTitleButton

# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setStyleSheet [as 别名]
 def _getTitleButton(self, 
                     parentWidget = None,
                     title        = '', 
                     showExpanded = True ):
     """
     Return the group box title push button. The push button is customized 
     such that it appears as a title bar at the top of the group box. 
     If the user clicks on this 'title bar' it sends a signal to open or 
     close the group box.
     
     @param parentWidget: The parent dialog or group box containing this 
                          widget.
     @type  parentWidget: PM_Dialog or PM_GroupBox
     
     @param title: The button title.
     @type  title: str 
     
     @param showExpanded: dDetermines whether the expand or collapse image is 
                          displayed on the title button.
     @type  showExpanded: bool
                          
     @see: L{_getTitleButtonStyleSheet()}
     
     @Note: Including a title button should only be legal if the parentWidget
            is a PM_Dialog.
     """
     
     button  = QPushButton(title, parentWidget)
     button.setFlat(False)
     button.setAutoFillBackground(True)
     
     button.setStyleSheet(self._getTitleButtonStyleSheet(showExpanded))     
     
     return button
开发者ID:ematvey,项目名称:NanoEngineer-1,代码行数:36,代码来源:PM_GroupBox.py

示例2: getTitleButton

# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setStyleSheet [as 别名]
    def getTitleButton(self, title, parent=None, showExpanded=True): #Ninad 070206
        """ Return the groupbox title pushbutton. The pushbutton is customized
        such that  it appears as a title bar to the user. If the user clicks on
        this 'titlebar' it sends appropriate signals to open or close the
        groupboxes   'name = string -- title of the groupbox
        'showExpanded' = boolean .. NE1 uses a different background
        image in the button's  Style Sheet depending on the bool.
        (i.e. if showExpanded = True it uses a opened group image  '^')
        See also: getGroupBoxTitleCheckBox , getGroupBoxButtonStyleSheet  methods
        """

        button  = QPushButton(title, parent)
        button.setFlat(False)
        button.setAutoFillBackground(True)

        button.setStyleSheet(self.getTitleButtonStyleSheet(showExpanded))
        button.setPalette(self.getTitleButtonPalette())

        #ninad 070221 set a non existant 'Ghost Icon' for this button
        #By setting such an icon, the button text left aligns!
        #(which what we want :-) )
        #So this might be a bug in Qt4.2.  If we don't use the following kludge,
        #there is no way to left align the push button text but to subclass it.
        #(could mean a lot of work for such a minor thing)  So OK for now

        button.setIcon(geticon("ui/actions/Properties Manager/GHOST_ICON"))

        return button
开发者ID:ematvey,项目名称:NanoEngineer-1,代码行数:30,代码来源:PropertyManagerMixin.py

示例3: windowTitle

# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setStyleSheet [as 别名]
class windowTitle(QFrame):
    def __init__(self, parent, closeButton=True):
        QFrame.__init__(self, parent)
        self.setMaximumSize(QSize(9999999,22))
        self.setObjectName("windowTitle")
        self.hboxlayout = QHBoxLayout(self)
        self.hboxlayout.setSpacing(0)
        self.hboxlayout.setContentsMargins(0,0,4,0)

        self.label = QLabel(self)
        self.label.setObjectName("label")
        self.label.setStyleSheet("padding-left:4px; font:bold 11px; color: #FFFFFF;")

        self.hboxlayout.addWidget(self.label)

        spacerItem = QSpacerItem(40,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
        self.hboxlayout.addItem(spacerItem)

        if closeButton:
            self.pushButton = QPushButton(self)
            self.pushButton.setFocusPolicy(Qt.NoFocus)
            self.pushButton.setObjectName("pushButton")
            self.pushButton.setStyleSheet("font:bold;")
            self.pushButton.setText("X")

            self.hboxlayout.addWidget(self.pushButton)

        self.dragPosition = None
        self.mainwidget = self.parent()
        self.setStyleSheet("""
            QFrame#windowTitle {background-color:#222222;color:#FFF;}
        """)

        # Initial position to top left
        self.dragPosition = self.mainwidget.frameGeometry().topLeft()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.mainwidget.frameGeometry().topLeft()
            event.accept()

    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton:
            self.mainwidget.move(event.globalPos() - self.dragPosition)
            event.accept()
开发者ID:Pardus-Linux,项目名称:yali,代码行数:47,代码来源:YaliDialog.py

示例4: Delegate

# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setStyleSheet [as 别名]
class Delegate(QStyledItemDelegate):

    def createEditor(self, parent, option, index):
        if index.isValid() and index.column() == 1:
            item = index.internalPointer()
            if isinstance(item.data, Attribute):
                attr = item.data
                if isinstance(attr.typ, VEnum):
                    editor = SpecialComboBox(parent)
                    editor.delegate = self
                    editor.setEditable(True)
                    editor.addItems(attr.typ.labels)
                elif isinstance(attr.typ, VBool):
                    editor = SpecialComboBox(parent)
                    editor.delegate = self
                    editor.setEditable(True)
                    editor.addItems(["False", "True"])
                else:
                    editor = QLineEdit(parent)
                return editor

    def setEditorData(self, editor, index):
        if isinstance(editor, QComboBox):
            i = editor.findText(index.data(Qt.EditRole).toString())
            if i > -1:
                editor.setCurrentIndex(i)
            else:
                editor.setEditText(index.data(Qt.EditRole).toString())
            editor.lineEdit().selectAll()
        else:
            return QStyledItemDelegate.setEditorData(self, editor, index)

    def setModelData(self, editor, model, index):
        if isinstance(editor, QComboBox):
            model.setData(index, QVariant(editor.currentText()), Qt.EditRole)
        else:
            return QStyledItemDelegate.setModelData(self, editor, model, index)

    def paint(self, painter, option, index):
        # If we are looking at a method then draw a button
        # http://www.qtcentre.org/threads/26916-inserting-custom-Widget-to-listview?p=128623#post128623
        if not hasattr(self, "blue_button"):
            self.blue_button = QPushButton()
            self.blue_button.setStyleSheet("color: rgb(0, 0, 196)")
        if index.isValid() and \
                isinstance(index.internalPointer().data, Method):
            item = index.internalPointer()
            opt = QStyleOptionButton()
            style = QApplication.style()
            # If method is running, draw sunken
            if item.argvalue:
                opt.state |= QStyle.State_Enabled
                opt.state |= QStyle.State_Sunken
            # if method is allowed, draw blue
            elif self.method_allowed(item):
                opt.state |= QStyle.State_Enabled
                style = self.blue_button.style()
            # if we are hovering, draw highlight
            if option.state & QStyle.State_MouseOver:
                opt.state |= QStyle.State_MouseOver
            opt.rect = option.rect
            opt.text = index.internalPointer().name
            style.drawControl(QStyle.CE_PushButton, opt, painter,
                              self.blue_button)
        else:
            if option.state & QStyle.State_Selected:
                # Don't show delegates as highlighted
                option.state = option.state ^ QStyle.State_Selected
            QStyledItemDelegate.paint(self, painter, option, index)

    def method_allowed(self, item):
        sm = getattr(item.data.device, "stateMachine", None)
        valid_states = item.data.valid_states
        return sm is None or valid_states is None or sm.state in valid_states

    def editorEvent(self, event, model, option, index):
        if index.isValid() and isinstance(index.internalPointer().data, Method):
            # TODO: Drag seems to do the wrong thing here...
            if event.type() in [QEvent.MouseButtonPress,
                                QEvent.MouseButtonDblClick]:
                if self.method_allowed(index.internalPointer()):
                    model.setData(index, 0)
                return True
        QStyledItemDelegate.editorEvent(self, event, model, option, index)
开发者ID:dls-controls,项目名称:malcolm,代码行数:86,代码来源:delegate.py


注:本文中的PyQt4.Qt.QPushButton.setStyleSheet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。