Nineteen --QFontComboBox study concluded GUI learning

We learned last chapter QComboBox usage of this chapter we look at it in a more commonly used subclass: QFontComboBox ().

I. Description :

  QFontComboBox () is QComboBox () in a subclass, but its contents can not be edited, is mainly used to select font.

II. Function

  1. Set and get the current font

QFontComboBox.setCurrentFont (Self, f: QtGui.QFont)       # set the font 
QFontComboBox.currentFont ()                              # Gets the font -> QFont

Note that the font is Arial currently displayed, even chose another font in the text box display are italicized.

  2. Set the font filter

  Since the control provides many types of font can be selected, we can provide a filter for filtering option controls

QFontComboBox.setFontFilters (Self, Filters: typing.Union [ ' QFontComboBox.FontFilters ' , ' QFontComboBox.FontFilter ' ])
 # of the type: 'QFontComboBox.FontFilter' 
AllFonts = ...            # All fonts
 ScalableFonts = ...       # scalable 
NonScalableFonts = ...     # unscalable 
MonospacedFonts = ...     # monospaced font 
ProportionalFonts = ...    # proportional fonts

III. Signal

  In addition to the inherited superclass signal, QFontComboBox () there is another signal

QFontComboBox.currentFontChanged(self, f: QtGui.QFont)

  Signal is also passed as a parameter of the selected font. We can use

from PyQt5.Qt Import *
 Import SYS 

class the Window (the QWidget):
     DEF  the __init__ (Self): 
        Super (). the __init__ () 
        self.UI_test () 



    DEF UI_test (Self): 
        FCB = QFontComboBox (Self) 
        fcb.resize ( 200 is, 30 ) 
        fcb.setEditable (False)    # general font selection controls that can not be edited 
        self.resize (500, 300 ) 
        self.fcb = FCB 
        self.label = QLabel (Self) 
        self.label.move ( 100, 100 )
        self.label.setText('hello,你是谁?')
        fcb.currentFontChanged.connect(self.font_change)

    def font_change(self,font):
        self.label.setFont(font)
        self.fcb.setFont(font)
        pass
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
QFontComboBox () Case

  It is to this effect

  By choosing the font, change the font selection box and label in the font.

Guess you like

Origin www.cnblogs.com/yinsedeyinse/p/10962326.html