class Font(object): def __init__(self, name=None, size=None, font=None): if font is not None: self.font = font else: assert name self.font = QFont(name) if size: self.font.setPixelSize(size) def qfont(self): return self.font def set_bold(self, bold=True): self.font.setBold(bold) # def size(self): # return self.font.pixelSize() # # def set_size(self, size): # self.font.setPixelSize(size) def adjust_size(self, increment=1): size = self.font.pointSize() print("pontSize is", size) self.font.setPointSize(size + increment) def increase_size(self, increment=1): size = self.font.pointSize() print("pontSize is", size) self.font.setPointSize(size + increment)
def __init__(self, name=None, size=None, font=None): if font is not None: self.font = font else: assert name self.font = QFont(name) if size: self.font.setPixelSize(size)
def __init__(self, parent, text="", font=None): super().__init__(parent, text) if font is not None: if isinstance(font, str): size, weight, family = font.split(" ", 3) assert size.endswith("px") font = QFont(family) font.setPixelSize(int(size[:-2])) weight = weight.lower() if weight == "regular": font.setWeight(QFont.Normal) elif weight == "medium": font.setWeight(QFont.DemiBold) elif weight == "bold": font.setWeight(QFont.Bold) else: raise Exception("Unknown weight") font = fsui.Font(font) self.set_font(font)
def __init__(self, name, size): qfont = QFont(name) qfont.setPixelSize(size) super().__init__(qfont)
def initialize_qt_style(qapplication, theme): print("Available QT styles:", QStyleFactory.keys()) qapplication.setStyle(QStyleFactory.create("Fusion")) pa = QPalette() # background = QColor("#f6f5f4") # color = fsui.Color(0xAEAEAE).lighten(0.065) # color = fsui.Color(0xAEAEAE).lighten(0.05) # background = QColor(color.to_hex()) background = QColor("#C2C2C2") text = "#000000" text_disabled = "#777777" pa.setColor(QPalette.Window, background) pa.setColor(QPalette.AlternateBase, background) pa.setColor(QPalette.Button, background) pa.setColor(QPalette.Highlight, QColor(0x66, 0x88, 0xBB)) set_colors(pa, QPalette.Base, "#E8E8E8", "#C0C0C0") set_colors(pa, QPalette.Text, text, text_disabled) set_colors(pa, QPalette.WindowText, text, text_disabled) set_colors(pa, QPalette.ButtonText, text, text_disabled) # pa.setColor(QPalette.Base, QColor(0xE8, 0xE8, 0xE8)) # pa.setColor(QPalette.Disabled, QPalette.Base, QColor(0xC0, 0xC0, 0xC0)) # pa.setColor(QPalette.Text, QColor(0xFF, 0x00, 0x00)) # pa.setColor(QPalette.Disabled, QPalette.Text, QColor(0xFF, 0x00, 0x00)) # Labels # pa.setColor(QPalette.WindowText, QColor(0x00, 0xFF, 0x00)) # pa.setColor( # QPalette.Disabled, QPalette.WindowText, QColor(0x00, 0x88, 0x00) # ) # Buttons # pa.setColor(QPalette.ButtonText, QColor(0x00, 0xFF, 0x00)) # pa.setColor( # QPalette.Disabled, QPalette.ButtonText, QColor(0x00, 0x88, 0x00) # ) # pa.setColor(QPalette.Base, QColor(0xEE, 0xEE, 0xEE)) # pa.setColor(QPalette.Base, QColor(0xFF, 0xFF, 0xFF)) # pa.setColor(QPalette.Disabled, QPalette.Text, QColor(0x66, 0x66, 0x66)) # pa.setColor(QPalette.Mid, QColor(0xFF, 0x00, 0x00)) # pa.setColor(QPalette.Window, QColor("#aeaeae")) # pa.setColor(QPalette.AlternateBase, QColor("#aeaeae")) # pa.setColor(QPalette.Button, QColor("#aeaeae")) qapplication.setPalette(pa) # pa.setColor(QPalette.Window, QColor(0x50, 0x50, 0x50)) # pa.setColor(QPalette.WindowText, Qt.white) # pa.setColor(QPalette.Base, QColor(25, 25, 25)) # pa.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) # pa.setColor(QPalette.ToolTipBase, Qt.white) # pa.setColor(QPalette.ToolTipText, Qt.white) # pa.setColor(QPalette.Text, Qt.white) # pa.setColor(QPalette.Button, QColor(0x58, 0x58, 0x58)) # pa.setColor(QPalette.ButtonText, Qt.white) # pa.setColor(QPalette.BrightText, Qt.red) # pa.setColor(QPalette.Link, QColor(42, 130, 218)) # pa.setColor(QPalette.Highlight, QColor(255, 0, 0)) # pa.setColor(QPalette.HighlightedText, Qt.black) # qapplication.setPalette(pa) # Choice:: # QStandardItemModel:: # QComboBoxPrivateContainer:: # QBoxLayout:: # QComboBoxListView:: # QWidget::qt_scrollarea_viewport # QWidget::qt_scrollarea_hcontainer # QScrollBar:: # QBoxLayout:: # QWidget::qt_scrollarea_vcontainer # QScrollBar:: # QBoxLayout:: # QItemSelectionModel:: # QComboMenuDelegate:: # QComboBoxPrivateScroller:: # QComboBoxPrivateScroller:: # FIXME: Make stylesheet use scaling function for numbers qapplication.setStyleSheet(f""" QToolTip {{ background-color: #efe4ab; border: 1px solid #958a62; padding-top: 4px; padding-right: 8px; padding-bottom: 4px; padding-left: 8px; padding: 0px; padding-top: 2px; padding-right: 4px; padding-bottom: 2px; padding-left: 4px; /* color: #FFFFFF; background-color: #2A82DA; border: 1px solid white; */ }} QPushButton {{ padding-right: 12px; padding-left: 12px; }} QPushButton:disabled {{ color: #777777; }} /* QLineEdit {{ padding-top: {theme.textfield_padding().top}px; padding-right: {theme.textfield_padding().right}px; padding-left: {theme.textfield_padding().left}px; padding-bottom: {theme.textfield_padding().bottom}px; }} */ /* Placeholder text. It will be made partially transparent by Qt */ /* FIXME: This only works when initially showing the widget :( */ /* TODO: Move color logic to fsui.TextField instead then... :( */ /* DONE! */ /* QLineEdit[text=""] {{ color: #660000; }} QLineEdit[text!=""] {{ color: #000000; }} */ /* QSpinBox {{ padding-top: 2px; padding-bottom: 2px; padding-right: 4px; padding-left: 4px; }} */ QCheckBox {{ spacing: 5px; }} QCheckBox::indicator {{ width: 18px; height: 18px; }} """) # try: # launcher_font_size = int( # Settings.instance().get("launcher_font_size") # ) # except ValueError: # if fusion_variant == "fws": # launcher_font_size = 13 # else: # launcher_font_size = 0 # if launcher_font_size: # print("FONT: Override size {}".format(launcher_font_size)) # font.setPointSize(launcher_font_size) # if fusion_variant == "fws": # font = QFont("Roboto") # font.setPointSizeF(10.5) # font.setHintingPreference(QFont.PreferNoHinting) # font.setHintingPreference(QFont.PreferNoHinting) # font = QFont("Saira Condensed", 16, QFont.Medium) font = QFont("Roboto", 15, QFont.Normal) font.setPixelSize(15) qapplication.setFont(font)