⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.lxp@lxpwrap=x7947_252ehtm.htm

📁 GUI Programming with Python
💻 HTM
📖 第 1 页 / 共 3 页
字号:
            painter.setPen(QPen(colorGroup.foreground(), 2, QPen.DotLine))        else:            painter.setPen(QPen(colorGroup.foreground(), 2))        if fill:            oldbrush=painter.brush()            painter.setPen(colorGroup.foreground())            painter.setBrush(fill)        painter.drawRect(x + 2, y + 2, w - 2, h - 2)        painter.setPen(oldpen)        painter.setBrush(oldbrush)    def drawRect(self, painter, x, y, w, h, color, lineWidth, fill):        qDrawPlainRect(painter, x, y, w, h, color, lineWidth, fill)    def drawRectStrong(self, painter, x, y, w, h, colorGroup,                             sunken, lineWidth, midLineWidth, fill):        qDrawPlainRect(painter, x, y, w, h, colorGroup.foreground(),                       sunken, lineWidth *2, fill)    def drawSeparator(self, painter, x1, y1, x2, y2, colorGroup,                            sunken, lineWidth, midLineWidth):        painter.save()        painter.setPen(colorGroup.foreground, lineWidth)        painter.drawLine(x1, y1, x2, y2)        painter.restore()    def drawroundrect(self, painter, x, y, w, h):        painter.drawRoundRect(x, y, w, h, 5, 50)    def roundRectRegion(self, rect, r):        x=rect.x()        y=rect.y()        right=x1+rect.right()        bottom=y1+rect.bottom()        a=QPointArray([8, x+r, y, right-r, y,                      right, y + r, right, bottom-r,                      right-r, bottom, x+r, bottom,                      x, bottom-r, x, y+r])        region=QRegion(a)        d=r*2-1        region.unite(QRegion(x, y, r*2, r*2, QRegion.Ellipse))        region.unite(QRegion(right - d, y, r*2, r*2, QRegion.Ellipse))        region.unite(QRegion(x, bottom-d, r*2, r*2, QRegion.Ellipse))        region.unite(QRegion(right-d, bottom-d, r*2, r*2, QRegion.Ellipse))        return region    #    # Tab    #    def drawTab(self, painter, tabBar, tab, selected):        a=QPointArray(10)        a.setPoint(0, 0, -1)        a.setPoint(1, 0, 0)        # Nasty! r is a private member of QTab. We shouldn't access it.        y=tab.r.height()-2        x=y/2        x=x+1        a.setPoint(2, x, y-1)        x=x+1        a.setPoint(3, x, y)        x=x+1        y=y+1        a.setPoint(3, x, y)        a.setPoint(4, x, y)        right=tab.r.width()-1        for i in range(5):            a.setPoint(9-i, right - a.point(i)[0], a.point(i)[1])        for i in range(10):            a.setPoint(i, a.point(i)[0], tab.r.height() - 1 - a.point(i)[1])        a.translate(tab.r.left(), tab.r.top())        if selected:            painter.setBrush(tabBar.colorGroup().background())        else:            painter.setBrush(tabBar.colorGroup().light())        painter.setPen(tabBar.colorGroup().foreground())        painter.drawPolygon(a)        painter.setBrush(Qt.NoBrush)    def drawTabMask(self, painter, tabbar, tab, selected):        painter.drawRect(tab.r)    #    # Sliders    #    def drawSlider(self, painter, x, y, w, h, colorGroup,                         orientation, tickAbove, tickBelow):        pass    def drawSliderMask(self, painter, x, y, w, h,                             orientation, tickAbove, tickBelow):        painter.fillRect(x, y, w, h, Qt.color1)    def drawSliderGrooveMask(self, painter, x, y, w, h, coord, orientation):        colorGroup=QColorGroup(Qt.color1, Qt.color1, Qt.color1, Qt.color1,                               Qt.color1, Qt.color1, Qt.color1, Qt.color1,                               Qt.color0)        if orientation==Qt.Horizontal:            painter.fillRect(x, y, w, h, Qt.color1)        else:            painter.fillRect(x, y, w, h, Qt.color1)    #    # Buttons and pushbuttons    #    def drawButton(self, painter, x, y, w, h, colorGroup,                   sunken=FALSE, fill=None):        oldBrush=painter.brush()        if fill != None:            painter.setBrush(fill)        self.drawroundrect(painter, x, y, w, h)        painter.setBrush(oldBrush)    def drawPushButtonlabel (self, button, painter):        QWindowsStyle.drawPushButonLabel(self, button, painter)    def drawPushButton(self, button, painter):        colorGroup=button.colorGroup()        (x1, y1, x2, y2)=button.rect().coords()        painter.setPen(colorGroup.foreground())        painter.setBrush(QBrush(colorGroup.button(),                                Qt.NoBrush))        if button.isDown():            brush=QBrush()            brush.setColor(colorGroup.highlight())            brush.setStyle(QBrush.SolidPattern)            fill=brush        elif button.isOn():            brush=QBrush()            brush.setColor(colorGroup.mid())            brush.setStyle(QBrush.SolidPattern)            fill=brush        else:            fill=colorGroup.brush(colorGroup.Button)        if button.isDefault():            painter.setPen(QPen(Qt.black, 3))            self.drawroundrect(painter, x1, y1, x2-x1+1, y2-y1+1)            painter.setPen(QPen(Qt.black, 1))            x1=x1+4            y1=y1+4            x2=x2-4            y2=y2-4        if button.isOn() or button.isDown():            sunken=TRUE        else:            sunken=FALSE        self.drawButton(painter, x1, y1, x2-x1+1, y2-y1+1,                        colorGroup, sunken, fill)        if button.isMenuButton():            dx=(y1-y2-4)/3            self.drawArrow(painter, Qt.DownArrow, FALSE,                           x2-dx, dx, y1, y2-y1,                           colorGroup, button.isEnabled())        if painter.brush().style != Qt.NoBrush:            painter.setBrush(Qt.NoBrush)    def drawPushButtonLabel(self, button, painter):        r=button.rect()        (x, y, w, h)=r.rect()        (x1, y1, x2, y2)=button.rect().coords()        dx=0        dy=0        if button.isMenuButton():            dx=(y2-y1)/3        if dx or dy:            p.translate(dx,dy)        x=x+2        y=y+2        w=w-4        h=h-4        g=button.colorGroup()        if button.isDown() or button.isOn():            pencolour=button.colorGroup().brightText()        else:            pencolour=button.colorGroup().buttonText()        self.drawItem(painter, x, y, w, h,                          Qt.AlignCenter|Qt.ShowPrefix,                          g, button.isEnabled(),                          button.pixmap(), button.text(), -1,                          pencolour)        if dx or dy:            painter.translate(-dx,-dy)    def drawBevelButton(self, painter, x, y, w, h, colorGroup,                        sunken=FALSE, fill=None):        self.drawButton(painter, x, y, w, h, colorGroup, sunken, fill)    def buttonRect(self, x, y, w, h):        return QRect(x+3, y+2, w-6, h-4)    def drawButtonMask(self, p, x, y, w, h):        self.drawroundrect(p, x, y, w, h)    #    # Radio Button    #    def drawExclusiveIndicator(self, painter, x, y, w, h, colorGroup,                                     on, down, enabled):        painter.eraseRect(x, y, w, h)        painter.drawEllipse(x, y, w, h)        if on:            painter.setBrush(QBrush(colorGroup.foreground(), \            QBrush.SolidPattern))                        painter.drawEllipse(x + 3, y + 3, w - 6, h -6)    def drawExclusiveIndicatorMask(self, painter, x, y, w, h, on):        painter.fillRect(x, y, w, h, QBrush(Qt.color1))    #    # Checkbox    #    def drawIndicator(self, painter, x, y, w, h, colorGroup,                            state, down, enabled):        painter.save()        if enabled:            painter.setPen(QPen(colorGroup.foreground(), 1, \                           QPen.SolidLine))        else:            painter.setPen(QPen(colorGroup.mid(), 1, QPen.SolidLine))        if state==QButton.Off:            painter.setBrush(QBrush(colorGroup.background(), \                                    QBrush.SolidPattern))        elif state==QButton.NoChange:            painter.setBrush(QBrush(colorGroup.dark(), \                             QBrush.SolidPattern))        else:            painter.setBrush(QBrush(colorGroup.background(), \                             QBrush.SolidPattern))        painter.drawRect(x, y, w, h)        if state==QButton.On:            painter.drawLine(x, y, x + w, y + h)            painter.drawLine(x, y + h - 1, x + w - 1, y)        painter.restore()    def drawIndicatorMask(self, painter, x, y, w, h, state):        painter.fillRect(x, y , w + 3, h, QBrush(Qt.color1))    #    # Menu bar    #    def drawMenuBarItem(self, painter, x, y, w, h, menuItem, \                        colorGroup, enabled, active):        """        Not subclassable?        """        self.drawItem(painter, x, y, w, h,                      Qt.AlignCenter | Qt.ShowPrefix | Qt.DontClip | \                      Qt.SingleLine, colorGroup, menuItem.pixmap(), \                      menuItem.text(), -1, QColorGroup.buttonText())    #    # These items are not (yet) implemented in PyQt    #    def drawPopupMenuItem (self, painter, checkable, maxpmw, tab,                                 menuItem, palette, act, enabled,                                 x, y, w, h):        """        Not implemented in PyQt        """        pass    def extraPopupMenuItemWidth (self, checkable, maxpmw,                                       menuItem, fontMetrics):        """        Not implemented in PyQt        """        pass    def popupMenuItemHeight (self, checkable, menuItem, fontMetrics):        """        Not implemented in PyQt        """        pass        </PRE></DIV></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2">Using styles from PyQt</A></H2><P>Using these custom styles in your own application        is as simple as using the built-in styles. I have adapted the        small <TTCLASS="FILENAME">themes.py</TT> example that comes with        <SPANCLASS="APPLICATION">BlackAdder</SPAN> or        <SPANCLASS="APPLICATION">PyQt</SPAN> to show off the new custom        styles:</P><DIVCLASS="EXAMPLE"></A><P><B>Example 22-5. Testing styles</B></P><PRECLASS="PROGRAMLISTING">## styletester.py - a testbed for styles.# Based on Phil's adaption of my translation of the# Qt themes example app.#FALSE=0TRUE=1import os, sysfrom qt import *from macstyle import MacStyleclass ButtonsGroups(QVBox):  def __init__(self, parent=None, name=None):    QVBox.__init__(self, parent, name)    # Create widgets which allow easy layouting    box1=QHBox(self)    box2=QHBox(self)    # first group    # Create an exclusive button group    grp1=QButtonGroup( 1                     , QGroupBox.Horizontal                     , "Button Group 1 (exclusive)"                     , box1                     )    grp1.setExclusive(TRUE)    # insert 3 radiobuttons    rb11=QRadioButton("&#38;Radiobutton 1", grp1)    rb11.setChecked(TRUE)    QRadioButton("R&#38;adiobutton 2", grp1)    QRadioButton("Ra&#38;diobutton 3", grp1)    # second group    # Create a non-exclusive buttongroup    grp2=QButtonGroup( 1                     , QGroupBox.Horizontal                     , "Button Group 2 (non-exclusive)"                     , box1                     )    grp2.setExclusive(FALSE)    # insert 3 checkboxes    QCheckBox("&#38;Checkbox 1", grp2)    cb12=QCheckBox("C&#38;heckbox 2", grp2)    cb12.setChecked(TRUE)    cb13=QCheckBox("Triple &#38;State Button", grp2)    cb13.setTristate(TRUE)    cb13.setChecked(TRUE)    # third group    # create a buttongroup which is exclusive for radiobuttons and    # non-exclusive for all other buttons    grp3=QButtonGroup( 1                     , QGroupBox.Horizontal                     , "Button Group 3 (Radiobutton-exclusive)"                     , box2                     )    grp3.setRadioButtonExclusive(TRUE)    # insert three radiobuttons    self.rb21=QRadioButton("Rad&#38;iobutton 1", grp3)    self.rb22=QRadioButton("Radi&#38;obutton 2", grp3)    self.rb23=QRadioButton("Radio&#38;button 3", grp3)    self.rb23.setChecked(TRUE)    # insert a checkbox...    self.state=QCheckBox("E&#38;nable Radiobuttons", grp3)    self.state.setChecked(TRUE)    # ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State()    self.connect(self.state, SIGNAL('clicked()'),self.slotChangeGrp3State)    # fourth group    # create a groupbox which lays out its childs in a column    grp4=QGroupBox( 1                    , QGroupBox.Horizontal                    , "Groupbox with normal buttons"                    , box2                    )    # insert two pushbuttons...    QPushButton("&#38;Push Button", grp4)    bn=QPushButton("&#38;Default Button", grp4)    bn.setDefault(TRUE)    tb=QPushButton("&#38;Toggle Button", grp4)    # ...and make the second one a toggle button    tb.setToggleButton(TRUE)    tb.setOn(TRUE)  def slotChangeGrp3State(self):    self.rb21.setEnabled(self.state.isChecked())    self.rb22.setEnabled(self.state.isChecked())    self.rb23.setEnabled(self.state.isChecked())class LineEdits(QVBox):  def __init__(self, parent=None, name=None):    QVBox.__init__(self, parent, name)    self.setMargin(10)    # Widget for layouting    row1=QHBox(self)    row1.setMargin(5)    # Create a label    QLabel("Echo Mode: ", row1)    # Create a Combobox with three items...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -