示例#1
0
 def initFontWidget(self):
     self.fontDialog = QFontDialog()
     self.changeFontButton = QPushButton(self)
     self.fontDialog.setCurrentFont(QFont('Sans serif'))
     self.changeFontButton.setText('{0} {1}'.format(self.fontDialog.currentFont().family(),
                                                    self.fontDialog.currentFont().pointSize()))
     self.changeFontButton.clicked.connect(self.fontButtonClicked)
    def do_mouseDoubleClick(self, point):  ##鼠标双击
        pt = self.__view.mapToScene(point)  # 转换到Scene坐标,QPointF
        item = self.__scene.itemAt(pt, self.__view.transform())  # 获取光标下的绘图项
        if item is None:
            return

        className = str(type(item))  # 将类名称转换为字符串

        if className.find("QGraphicsRectItem") >= 0:  # 矩形框
            self.__setBrushColor(item)
        elif className.find(
                "QGraphicsEllipseItem") >= 0:  # 椭圆和圆都是 QGraphicsEllipseItem
            self.__setBrushColor(item)
        elif className.find("QGraphicsPolygonItem") >= 0:  # 梯形和三角形
            self.__setBrushColor(item)
        elif className.find("QGraphicsLineItem") >= 0:  # 直线,设置线条颜色
            pen = item.pen()
            color = item.pen().__color()
            color = QColorDialog.getColor(color, self, "选择线条颜色")
            if color.isValid():
                pen.setColor(color)
                item.setPen(pen)
        elif className.find("QGraphicsTextItem") >= 0:  # 文字,设置字体
            font = item.font()
            font, OK = QFontDialog.getFont(font)
            if OK:
                item.setFont(font)
示例#3
0
 def fontButtonClicked(self):
     ok = True
     font = QFontDialog.getFont(self)
     if font[1]:
         self.changeFontButton.setText('{0} {1}'.format(font[0].family(),
                                                        font[0].pointSize()))
         self.fontChangeTrigger.emit(font[0])
示例#4
0
 def choose_font(self):
     (ret, r_font) = QFontDialog().getFont(
         self._window.font(), self._window, 'Get some font',
         QFontDialog.ScalableFonts | QFontDialog.MonospacedFonts)
     if ret:
         print('select ok')
         self._window.input_line.setText(r_font.__repr__())
     else:
         print('select cancelled')
 def open_dialog(self):
     response, font = QFontDialog().getFont(
         self.last_font,
         parent=self,
         title='Configuração da fonte.',
     )
     if response:
         self.label.setText(f'Fonte selecionada: {font.family()}')
         self.label.setFont(font)
         self.last_font = font
示例#6
0
 def font_app(self, checked):
     (ok, font) = QFontDialog.getFont(self)
     if ok:
         self.widget.setFont(font)
         self.widget.test_widget.formula.setFont(
             QFont(font.family(),
                   font.pointSize() + 8))
         self.widget.test_widget.answer.setFont(
             QFont(font.family(),
                   font.pointSize() + 8))
示例#7
0
文件: doc.py 项目: yimuchens/doc
 def setFont_(self):
     font, ok = QFontDialog.getFont()
     if ok:
         GlobalVars.CurrentFont = font
         if GlobalVars.CurrentDocument.SelBlocks:  # 处于选中状态
             for block in GlobalVars.CurrentDocument.SelBlocks:
                 if hasattr(block, "setFont_"):
                     block.setFont_(font)
         else:
             if hasattr(GlobalVars.CurrentBlock, "setFont_"):
                 GlobalVars.CurrentBlock.setFont_(font)
示例#8
0
    def chooseFont(self):
        """
        Selecione a fonte do texto
        """

        atual = self.tedit.currentFont()
        font, ok = QFontDialog.getFont(atual,
                                       self,
                                       options=QFontDialog.DontUseNativeDialog)

        if ok:
            self.tedit.setCurrentFont(font)
示例#9
0
 def openFontDialog(self):
     ok, font = QFontDialog.getFont()
     if ok:
         self.label_10.setFont(font)
         self.label_11.setFont(font)
         self.label_12.setFont(font)
         self.label_13.setFont(font)
         self.label_14.setFont(font)
         self.label_30.setFont(font)
         self.label_29.setFont(font)
         self.label_10.adjustSize()
         self.label_11.adjustSize()
         self.label_12.adjustSize()
         self.label_13.adjustSize()
         self.label_14.adjustSize()
         self.label_30.adjustSize()
         self.label_29.adjustSize()
示例#10
0
 def getFont(self):
     status, font = QFontDialog.getFont()
     if status:
         self.font = QFontInfo(font)
         self.fontName = self.font.family()
         self.fontSize = self.font.pointSize()
         self.fontBold = self.font.bold()
         self.fontItalic = self.font.italic()
         self.fontUnderline = self.font.underline()
         self.fontStrikeout = self.font.strikeOut()
         fontBold = '粗体' if self.fontBold else ''
         fontItalic = '斜体' if self.fontItalic else ''
         fontUnderline = '下划线' if self.fontUnderline else ''
         fontStrikeOut = '删除线' if self.fontStrikeout else ''
         self.fontSelect.setText('%s%s号%s%s%s%s' %
                                 (self.fontName, self.fontSize, fontBold,
                                  fontItalic, fontUnderline, fontStrikeOut))
示例#11
0
 def set_font(self):
     """Change the font of all widgets through QFontDialog.
     """
     self.parent.dialog = QFontDialog(self.parent)
     self.parent.dialog.setOption(QFontDialog.DontUseNativeDialog)
     self.parent.dialog.resize(800, 600)
     ret = self.parent.dialog.exec_()
     if ret:
         font = self.parent.dialog.selectedFont()
         family = str(font.family())
         size = str(font.pointSize())
         font_css = str(self.parent.parent_dir / "font.qss")
         with open(font_css, "w") as f:
             f.write("* {\n")
             f.write('    font-family: "{}";\n'.format(family))
             f.write('    font-size: {}px;\n'.format(size))
             f.write("}")
         self.parent.setStyleSheet("")
         with open(font_css, "r") as f:
             self.parent.setStyleSheet(f.read())
示例#12
0
 def showDialog(self):
     ok, font = QFontDialog.getFont()
     if ok:
         self.lbl.setFont(font)
示例#13
0
 def showDialog(self):
     font, ok = QFontDialog.getFont()
     if ok:
         # self.lbl.setFont(font)
         self.lbl.setFont(font)
示例#14
0
文件: color.py 项目: Yobmod/dmltests
 def font_choice(self) -> None:
     valid, font = QFontDialog.getFont()
     if valid is True:
         self.styleChoice.setFont(font)
示例#15
0
    def changeFont(self):
        ok, font = QFontDialog.getFont(self)

        if ok:
            self.textedit.setFont(font)
示例#16
0
 def fontChange(self):
     (font, ok) = QFontDialog.getFont(QFont("Helvetica[Cronyx]", 10), self)
     if ok:
         self.textEdit.setCurrentFont(font)
示例#17
0
 def actionFont_triggered(self):
     font = QFontDialog.getFont()
     self.textEdit.setFont(font[1])
示例#18
0
 def set_markdown_font(self):
     (ok, font) = QFontDialog.getFont(self.md_text_edit.font(), self,
                                      "Markdown Font")
     self.md_text_edit.setFont(font)
    def change_font(self, name):
        """Changes the font used throughout the application.
        Currently triggered via a menu action.

        name: Used to specify whether the font should be resized or
              changed to a different font family.
        """

        # Get the context.
        if name == "":
            # Case 1: Default Change Font menu option.
            ok, f = QFontDialog.getFont(self.window)
            start = False
        elif name == "+" or name == "-":
            # Case 2: Increase/Decrease font size menu option.
            f = self.ui.table_PS.font()
            f_size = f.pointSize() + 2 if name == "+" else f.pointSize() - 2
            f = f.toString().split(",")[0]
            f = QFont(f, f_size)
            ok, start = True, False
        else:
            if type(name) == str:
                # Case 3.1: Init with pref.json
                f = name.split("%")
                f = QFont(f[0], int(f[1]))
            else:
                # Case 3.2: Init without pref.json (first launch).
                f = name
            ok, start = True, True
        if ok:
            # Change the font for everything (within reason).
            self.font = f
            new_font = f
            big_font = QFont(f.toString().split(",")[0], f.pointSize() + 6)

            # self.ui.tabs.setFont(new_font)

            # PS tab
            self.ui.table_PS.setFont(new_font)
            self.ui.table_PS.horizontalHeader().setFont(new_font)
            self.ui.text_browser_PS.setFont(big_font)
            self.ui.refresh_pch_btn.setFont(new_font)
            self.ui.btn_dwn_all.setFont(new_font)

            # Local tab
            self.ui.table_local.setFont(new_font)
            self.ui.table_local.horizontalHeader().setFont(new_font)
            self.ui.text_browser_local.setFont(big_font)
            self.ui.back_btn_local.setFont(new_font)
            self.ui.check_for_updates_btn.setFont(new_font)
            self.ui.update_patch_notes.setFont(new_font)
            self.ui.btn_show_routing.setFont(new_font)
            self.ui.page_label.setFont(new_font)
            self.ui.back_btn.setFont(new_font)
            self.ui.btn_next_page.setFont(new_font)
            self.ui.btn_prev_page.setFont(new_font)

            # SD tab
            self.ui.sd_tree.setFont(new_font)
            self.ui.table_sd_left.setFont(new_font)
            self.ui.table_sd_left.horizontalHeader().setFont(new_font)
            self.ui.table_sd_left.verticalHeader().setFont(new_font)
            self.ui.table_sd_right.setFont(new_font)
            self.ui.table_sd_right.horizontalHeader().setFont(new_font)
            self.ui.table_sd_right.verticalHeader().setFont(new_font)
            self.ui.delete_folder_sd_btn.setFont(new_font)
            self.ui.set_export_dir_btn.setFont(new_font)
            self.ui.import_all_btn.setFont(new_font)
            self.ui.import_all_ver_btn.setFont(new_font)

            # Folders tab
            self.ui.table_bank_local.setFont(new_font)
            self.ui.table_bank_local.horizontalHeader().setFont(new_font)
            self.ui.table_bank_left.setFont(new_font)
            self.ui.text_browser_viz.setFont(new_font)
            self.ui.table_bank_left.horizontalHeader().setFont(new_font)
            self.ui.table_bank_left.verticalHeader().setFont(new_font)
            self.ui.table_bank_right.setFont(new_font)
            self.ui.table_bank_right.horizontalHeader().setFont(new_font)
            self.ui.table_bank_right.verticalHeader().setFont(new_font)
            self.ui.back_btn_bank.setFont(new_font)
            self.ui.btn_save_bank.setFont(new_font)
            self.ui.btn_load_bank.setFont(new_font)
            self.ui.btn_clear_bank.setFont(new_font)
            self.ui.btn_export_bank.setFont(new_font)
            self.ui.text_browser_bank.setFont(big_font)

            if not start:
                for i in range(self.ui.table_PS.rowCount()):
                    self.ui.table_PS.cellWidget(i, 0).setFont(new_font)
                    self.ui.table_PS.cellWidget(i, 4).setFont(new_font)
                if self.ui.table_local.cellWidget(0, 0) is not None:
                    for i in range(self.ui.table_local.rowCount()):
                        self.ui.table_local.cellWidget(i, 0).setFont(new_font)
                        self.ui.table_local.cellWidget(i, 4).setFont(new_font)
                        self.ui.table_local.cellWidget(i, 5).setFont(new_font)
                for i in range(32):
                    # Need trys here in case the table does not have a
                    # cell widget there yet.
                    try:
                        self.ui.table_sd_left.cellWidget(i, 1).setFont(new_font)
                    except AttributeError:
                        pass
                    try:
                        self.ui.table_sd_left.cellWidget(i, 2).setFont(new_font)
                    except AttributeError:
                        pass
                    try:
                        self.ui.table_sd_right.cellWidget(i, 1).setFont(new_font)
                    except AttributeError:
                        pass
                    try:
                        self.ui.table_sd_right.cellWidget(i, 2).setFont(new_font)
                    except AttributeError:
                        pass
                    try:
                        self.ui.table_bank_left.cellWidget(i, 1).setFont(new_font)
                    except AttributeError:
                        pass
                    try:
                        self.ui.table_bank_left.cellWidget(i, 2).setFont(new_font)
                    except AttributeError:
                        pass
                    try:
                        self.ui.table_bank_right.cellWidget(i, 1).setFont(new_font)
                    except AttributeError:
                        pass
                    try:
                        self.ui.table_bank_right.cellWidget(i, 2).setFont(new_font)
                    except AttributeError:
                        pass
                if self.ui.table_bank_local.cellWidget(0, 0) is not None:
                    for i in range(self.ui.table_bank_local.rowCount()):
                        self.ui.table_bank_local.cellWidget(i, 0).setFont(new_font)
示例#20
0
文件: pyn.py 项目: runew0lf/Pyn
 def changefont(self):
     dialog = QFontDialog()
     dialog.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
     dialog.exec()
     font = dialog.selectedFont()
     self.setFont(font)
    def fontDialog(self):
        (ok, font) = QFontDialog.getFont()

        if ok:
            self.textEdit.setFont(font)
示例#22
0
    def showDialog(self):

        font, OK = QFontDialog.getFont()
        if OK:
            self.label.setFont(font)
示例#23
0
class PenSetWidget(QWidget):

    penSizeTrigger = Signal(int)
    penColorTrigger = Signal(str)
    fontChangeTrigger = Signal(QFont)

    def __init__(self, parent=None):
        super().__init__(parent)

        self.paddingX = 5
        self.paddingY = 2
        self.iconWidth = self.iconHeight = 24
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        self.setWindowFlags(Qt.ToolTip)

        self.initWindows()

        self.prevSizeButton = self.penSize1
        self.penSize1.setChecked(True)
        self.presentColor.setStyleSheet('QPushButton { background-color: %s; }' % PENCOLOR)

    def generateButtons(self, parent=None):
        """ Generate buttons due to colorDic """
        self.colorButtons = []
        for color in self.colorList:
            button = QPushButton(parent)
            button.setObjectName(color[0])
            button.setStyleSheet('QPushButton { background-color: %s; }' % color[1])
            button.setFixedSize(self.iconWidth / 2, self.iconHeight / 2)
            button.setCheckable(True)
            self.colorButtons.append(button)

    def initWindows(self):
        self.mainLayout = QHBoxLayout()
        self.setLayout(self.mainLayout)
        self.mainLayout.setSpacing(0)
        self.mainLayout.setContentsMargins(5, 2, 5, 2)

        self.initPenSizeButtons()
        self.initFontWidget()
        self.initPenColorButtons()

        self.separator = QFrame(self)
        self.separator.setFrameShape(QFrame.VLine)
        self.separator.setFrameShadow(QFrame.Sunken)

        self.mainLayout.addWidget(self.penSize)
        self.mainLayout.addWidget(self.changeFontButton)
        self.mainLayout.addWidget(self.separator)

        self.mainLayout.addWidget(self.colorSet)

    def initPenSizeButtons(self):
        self.penSize = QWidget(self)
        self.penSizeLayout = QHBoxLayout()
        self.penSize.setLayout(self.penSizeLayout)
        # adjust pen size
        self.penSize1 = QPushButton(self.penSize)
        self.penSize1.setIcon(QIcon(":/resource/icon/pensize1.png"))
        self.penSize1.setObjectName('1')
        self.penSize1.setFixedSize(self.iconWidth, self.iconHeight)
        self.penSize1.setCheckable(True)

        self.penSize2 = QPushButton(self.penSize)
        self.penSize2.setIcon(QIcon(":/resource/icon/pensize2.png"))
        self.penSize2.setObjectName('2')
        self.penSize2.setFixedSize(self.iconWidth, self.iconHeight)
        self.penSize2.setCheckable(True)

        self.penSize3 = QPushButton(self.penSize)
        self.penSize3.setIcon(QIcon(":/resource/icon/pensize3.png"))
        self.penSize3.setObjectName('3')
        self.penSize3.setFixedSize(self.iconWidth, self.iconHeight)
        self.penSize3.setCheckable(True)

        self.sizeButtonGroup = QButtonGroup(self.penSize)
        self.sizeButtonGroup.addButton(self.penSize1)
        self.sizeButtonGroup.addButton(self.penSize2)
        self.sizeButtonGroup.addButton(self.penSize3)
        self.sizeButtonGroup.buttonClicked.connect(self.sizeButtonToggled)

        self.penSizeLayout.addWidget(self.penSize1)
        self.penSizeLayout.addWidget(self.penSize2)
        self.penSizeLayout.addWidget(self.penSize3)

        self.penSizeLayout.setSpacing(5)
        self.penSizeLayout.setContentsMargins(0, 0, 0, 0)

    def initPenColorButtons(self):
        self.colorSet = QWidget(self)
        self.colorLayout = QHBoxLayout()
        self.colorLayout.setSpacing(5)
        self.colorLayout.setContentsMargins(5, 0, 5, 0)
        self.colorSet.setLayout(self.colorLayout)

        self.presentColor = QPushButton(self.colorSet)
        self.presentColor.setFixedSize(self.iconWidth, self.iconHeight)
        self.presentColor.setEnabled(False)

        # adjust pen color

        self.colorPick = QWidget(self.colorSet)
        self.colorGrid = QGridLayout()
        self.colorGrid.setSpacing(0)
        self.colorGrid.setContentsMargins(5, 0, 5, 0)
        self.colorPick.setLayout(self.colorGrid)

        self.colorList = [('white'       ,       '#ffffff'),
                          ('red'         ,       '#ff0000'),
                          ('green'       ,       '#00ff00'),
                          ('blue'        ,       '#0000ff'),
                          ('cyan'        ,       '#00ffff'),
                          ('magenta'     ,       '#ff00ff'),
                          ('yellow'      ,       '#ffff00'),
                          ('gray'        ,       '#a0a0a4'),

                          ('black'       ,       '#000000'),
                          ('darkRed'     ,       '#800000'),
                          ('darkGreen'   ,       '#008000'),
                          ('darkBlue'    ,       '#000080'),
                          ('darkCyan'    ,       '#008080'),
                          ('darkMagenta' ,       '#800080'),
                          ('darkYellow'  ,       '#808000'),
                          ('darkGray'    ,       '#808080')]

        self.generateButtons()

        self.colorButtonGroup = QButtonGroup(self)
        for button in self.colorButtons:
            self.colorButtonGroup.addButton(button)
        self.colorButtonGroup.buttonClicked.connect(self.colorButtonToggled)

        # set the layout
        tmp = 0
        for x in range(0, 2):
            for y in range(0, int(len(self.colorList) / 2)):
                self.colorGrid.addWidget(self.colorButtons[tmp], x, y)
                tmp += 1

        self.colorGrid.setSpacing(0)
        self.colorGrid.setContentsMargins(0, 0, 0, 0)

        self.colorLayout.addWidget(self.presentColor)
        self.colorLayout.addWidget(self.colorPick)

    def initFontWidget(self):
        self.fontDialog = QFontDialog()
        self.changeFontButton = QPushButton(self)
        self.fontDialog.setCurrentFont(QFont('Sans serif'))
        self.changeFontButton.setText('{0} {1}'.format(self.fontDialog.currentFont().family(),
                                                       self.fontDialog.currentFont().pointSize()))
        self.changeFontButton.clicked.connect(self.fontButtonClicked)

    def showFontWidget(self):
        self.changeFontButton.show()
        self.penSize1.hide()
        self.penSize2.hide()
        self.penSize3.hide()

    def showPenWidget(self):
        self.changeFontButton.hide()
        self.penSize1.show()
        self.penSize2.show()
        self.penSize3.show()

    # slots
    def colorButtonToggled(self, button):
        self.presentColor.setStyleSheet('QPushButton { background-color: %s; }' % button.objectName())
        self.penColorTrigger.emit(button.objectName())

    def sizeButtonToggled(self, button):
        self.penSizeTrigger.emit(int(button.objectName()) * 2)

    def fontButtonClicked(self):
        ok = True
        font = QFontDialog.getFont(self)
        if font[1]:
            self.changeFontButton.setText('{0} {1}'.format(font[0].family(),
                                                           font[0].pointSize()))
            self.fontChangeTrigger.emit(font[0])