Ejemplo n.º 1
0
def get_font(family, fallback=None):
    """Return a font of the requested family, using fallback as alternative.

    If a fallback is provided, it is used in case the requested family isn't
    found.  If no fallback is given, no alternative is chosen and Qt's internal
    algorithms may automatically choose a fallback font.

    Parameters
    ----------
    family : str
      A font name.
    fallback : str
      A font name.

    Returns
    -------
    font : QFont object
    """
    font = QtGui.QFont(family)
    # Check whether we got what we wanted using QFontInfo, since exactMatch()
    # is overly strict and returns false in too many cases.
    font_info = QtGui.QFontInfo(font)
    if fallback is not None and font_info.family() != family:
        font = QtGui.QFont(fallback)
    return font
Ejemplo n.º 2
0
 def setNewStyleSheet(self, down_arrow_path):
     fontInfo = QtGui.QFontInfo(self.font())
     family = fontInfo.family()
     font_size = fontInfo.pixelSize()
     
      # stylesheet because of a border on the arrow that I dislike
     stylesheet = ["QComboBox { color: black;  font-size: " + str(font_size) + "px;",
         "font-family: " + family + ";  margin: 0px 0px 1px 1px;  border: 0px;",
         "padding: 1px 0px 0px 0px;}", # This (useless) line resolves a bug with the font color
         "QComboBox::drop-down { border: 0px; }" # Replaces the whole arrow of the combo box
         "QComboBox::down-arrow { image: url(" + down_arrow_path + ");",
         "width: 14px; height: 14px; }"]
     
     self.setStyleSheet(' '.join(stylesheet))