Qt是一款开源的、跨平台的C++开发框架,支持Windows、Linux、Mac系统,从1995发布第一版以来,发展迅猛,最开始是用于Nokia手机的Symbian(塞班)系统和应用程序开发,现在是用于嵌入式软件、桌面软件(比如WPS、VirtualBox)、Android软件等开发,到2023年12月,其最新的版本已经更新到了v6.6。
而Qt Creator是Qt的开源实现IDE,现在已经集成到了Qt.exe里,Qt Creator默认的颜色是白色,字体是跟随系统字体。它原来的白色太刺眼,系统字体对于编程有点古板。这里介绍Qt Creator的字体、颜色、主题样式设置,以Qt 5.14.2为例进行说明。
1 下载并安装微软雅黑字体
1.1 下载微软雅黑字体
微软雅黑字体,分为Microsoft YaHei mono字体、Microsoft YaHei字体,即一个带mono,另一个不带mono。推荐使用带mono的,它字体等宽,颜色也好看。
Microsoft YaHei mono字体地址: https://pan.baidu.com/s/1nG3m_plcfnrbNgksnep5_Q 提取码:in9h
下载之后,将其解压,得到MSYHMONO.ttf文件,右击MSYHMONO.ttf文件 --》再点击"为所有用户"安装即可,如图(1)所示:
1.2 启用Microsoft YaHei mono字体
点击QtCreator菜单栏上的[工具] --> 选项 --》
文本编辑器 --》字体 --》选中 Microsoft YaHei mono --》Apply
图(3) 在[文本编辑器] --》字体和颜色 --》选中"Microsoft YaHei Mono"
2 配置字体和颜色文件
2.1 编写vscode.xml
vscode.xml是一个仿造vscode软件经典黑色的配置文件,代码区和工具栏,都是亮酷的黑色,如图(1)所示:
图(3) vscode的字体样式 在D:\Qt\Qt5.14.2\Tools\QtCreator\share\qtcreator\styles目录,新建一个vscode.xml文件,将如下内容拷贝到vscode.xml;
//D:\Qt\Qt5.14.2\Tools\QtCreator\share\qtcreator\styles\vscode.xml
<?xml version="1.0" encoding="UTF-8"?><style-scheme version="1.0" name="VSCode"> <style name="Text" foreground="#9cdcfe" italic="false" background="#282c34"/> <style name="Link" /> <style name="Selection" background="#264f78"/> <style name="LineNumber" foreground="#858585" background="#1e1e1e"/> <style name="SearchResult" background="#333333"/> <style name="SearchScope" background="#1e1e1e"/> <style name="Parentheses" foreground="#dcdcaa" background="#343a40"/> <style name="CurrentLine" background="#707070"/> <style name="CurrentLineNumber" foreground="#c6c6c6" bold="true"/> <style name="Occurrences" background="#363636"/> <style name="Occurrences.Unused" foreground="#3b84b1"/> <style name="Occurrences.Rename" foreground="#ffaaaa" background="#553636"/> <style name="Number" foreground="#b5cea8"/> <style name="String" foreground="#ce9178"/> <style name="PrimitiveType" foreground="#569cd6"/> <style name="Type" foreground="#4ec9b0"/> <style name="Local"/> <style name="Field"/> <style name="Static" foreground="#569cd6" italic="false"/> <style name="VirtualMethod" italic="false"/> <style name="Function" foreground="#dcdcaa" italic="false"/> <style name="Keyword" foreground="#569cd6"/> <style name="Operator" foreground="#d4d4d4"/> <style name="Overloaded Operator" foreground="#dcdcaa"/> <style name="Preprocessor" foreground="#c586c0"/> <style name="Label" foreground="#569cd6"/> <style name="Comment" foreground="#6a9955"/> <style name="Doxygen.Comment" foreground="#6a9955"/> <style name="Doxygen.Tag" foreground="#00a0a0"/> <style name="VisualWhitespace" foreground="#c0c0c0"/> <style name="QmlLocalId" italic="false"/> <style name="QmlExternalId" foreground="#aaaaff" italic="false"/> <style name="QmlTypeId" foreground="#f3f351"/> <style name="QmlRootObjectProperty" italic="false"/> <style name="QmlScopeObjectProperty" italic="false"/> <style name="QmlExternalObjectProperty" foreground="#aaaaff" italic="false"/> <style name="JsScopeVar" foreground="#8888ff" italic="false"/> <style name="JsImportVar" foreground="#8888ff" italic="false"/> <style name="JsGlobalVar" foreground="#8888ff" italic="false"/> <style name="QmlStateName" italic="false"/> <style name="Binding" foreground="#ff5555"/> <style name="DisabledCode" foreground="#777777" background="#282c34"/> <style name="AddedLine" foreground="#55ffff"/> <style name="RemovedLine" foreground="#ff5555"/> <style name="DiffFile" foreground="#6a9955"/> <style name="DiffLocation" foreground="#ffff55"/> <style name="DiffFileLine" foreground="#000000" background="#d7d700"/> <style name="DiffContextLine" foreground="#000000" background="#8aaab6"/> <style name="DiffSourceLine" background="#8c2d2d"/> <style name="DiffSourceChar" foreground="#000000" background="#c34141"/> <style name="DiffDestLine" background="#2d8c2d"/> <style name="DiffDestChar" foreground="#000000" background="#41c341"/> <style name="Declaration" bold="false"/> <style name="Global" foreground="#9cdcfe" italic="false"/></style-scheme>
图(4) 在Qt的安装目录styles里,新建vscode.xml文件 2.2 启用VSCode字体样式
点击Qt Creator菜单栏上的[工具] --> 选项 --》 文本编辑器 --》字体和颜色,选中"VSCode" --》Apply
图(5) 启用VScode字体样式3 设置主题样式
3.1 新建oneDark.creatortheme主题文件
Qt Creator左侧的项目浏览框、文件打开框、右下角的输出框,都由Theme控制,它们保存在D:\Qt\Qt5.14.2\Tools\QtCreator\share\qtcreator\themes目录。
图(6) theme主题,控制的区域 在D:\Qt\Qt5.14.2\Tools\QtCreator\share\qtcreator\themes目录,新建一个oneDark.creatortheme文件,内容如下:
//D:\Qt\Qt5.14.2\Tools\QtCreator\share\qtcreator\themes\oneDark.creatortheme
[General]ThemeName=oneDarkPreferredStyles=FusionDefaultTextEditorColorScheme=oneDark.xml[Palette]shadowBackground=ff21252btext=ffabb2bftextDisabled=99abb2bftextHighlighted=ffd7dae0toolBarItem=ffabb2bftoolBarItemDisabled=99abb2bffancyBarsNormalTextColor=ffabb2bffancyBarsBoldTextColor=ffabb2bfhoverBackground=ff31363fselectedBackground=ff3a3f4bselectedBackgroundText=ffd7dae0normalBackground=ff282c34alternateBackground=ff31363ferror=ffe06c75warning=ffe5c07bsuccess=ff98c379message=ff61afefsplitter=ff181a1ftextColorLink=61afeftextColorLinkVisited=c678ddbackgroundColorDisabled=ff21252b[Colors];DS controls theme STARTDScontrolBackground=normalBackgroundDScontrolOutline=splitterDStextColor=textDSdisabledTextColor=textDisabledDSpanelBackground=ff454444DShoverHighlight=hoverBackgroundDScolumnBackground=ff363636DSfocusEdit=normalBackgroundDSfocusDrag=ff565656DScontrolBackgroundPressed=selectedBackgroundDScontrolBackgroundChecked=selectedBackgroundDSinteraction=selectedBackgroundDSsliderActiveTrack=ff7a7a7aDSsliderInactiveTrack=ff4d4d4dDSsliderHandle=ff4b5362DSsliderActiveTrackHover=ff7f7f7fDSsliderInactiveTrackHover=ff505050DSsliderHandleHover=ff7a7a7aDSsliderActiveTrackFocus=ffaaaaaaDSsliderInactiveTrackFocus=ff7a7a7aDSsliderHandleFocus=ff1d545cDSerrorColor=errorDScontrolBackgroundDisabled=backgroundColorDisabledDScontrolOutlineDisabled=ff4d4d4dDStextColorDisabled=textDisabledDStextSelectionColor=selectedBackgroundDStextSelectedTextColor=selectedBackgroundTextDSscrollBarTrack=ff4d4d4dDSscrollBarHandle=ff4b5362DScontrolBackgroundInteraction=ff4d4d4dDStranslationIndicatorBorder=splitterDSsectionHeadBackground=alternateBackgroundDSchangedStateText=messageDS3DAxisXColor=errorDS3DAxisYColor=successDS3DAxisZColor=message;DS controls theme ENDBackgroundColorAlternate=alternateBackgroundBackgroundColorDark=shadowBackgroundBackgroundColorHover=hoverBackgroundBackgroundColorNormal=normalBackgroundBackgroundColorDisabled=backgroundColorDisabledBackgroundColorSelected=selectedBackgroundBadgeLabelBackgroundColorChecked=textBadgeLabelBackgroundColorUnchecked=textBadgeLabelTextColorChecked=normalBackgroundBadgeLabelTextColorUnchecked=normalBackgroundCanceledSearchTextColor=errorComboBoxArrowColor=toolBarItemComboBoxArrowColorDisabled=toolBarItemDisabledComboBoxTextColor=fancyBarsNormalTextColorDetailsButtonBackgroundColorHover=hoverBackgroundDetailsWidgetBackgroundColor=shadowBackgroundDockWidgetResizeHandleColor=splitterDoubleTabWidget1stSeparatorColor=splitterDoubleTabWidget1stTabActiveTextColor=textDoubleTabWidget1stTabBackgroundColor=normalBackgroundDoubleTabWidget1stTabInactiveTextColor=textDoubleTabWidget2ndSeparatorColor=toolBarItemDisabledDoubleTabWidget2ndTabActiveTextColor=textDoubleTabWidget2ndTabBackgroundColor=selectedBackgroundDoubleTabWidget2ndTabInactiveTextColor=textEditorPlaceholderColor=shadowBackgroundFancyToolBarSeparatorColor=toolBarItemDisabledFancyTabBarBackgroundColor=shadowBackgroundFancyTabBarSelectedBackgroundColor=selectedBackgroundFancyTabWidgetDisabledSelectedTextColor=toolBarItemDisabledFancyTabWidgetDisabledUnselectedTextColor=toolBarItemDisabledFancyTabWidgetEnabledSelectedTextColor=fancyBarsBoldTextColorFancyTabWidgetEnabledUnselectedTextColor=fancyBarsBoldTextColorFancyToolButtonHoverColor=hoverBackgroundFancyToolButtonSelectedColor=selectedBackgroundFutureProgressBackgroundColor=shadowBackgroundIconsBaseColor=toolBarItemIconsDisabledColor=toolBarItemDisabledIconsInfoColor=messageIconsInfoToolBarColor=messageIconsWarningColor=warningIconsWarningToolBarColor=warningIconsErrorColor=errorIconsErrorToolBarColor=errorIconsRunColor=successIconsRunToolBarColor=successIconsStopColor=errorIconsStopToolBarColor=errorIconsInterruptColor=messageIconsInterruptToolBarColor=messageIconsDebugColor=toolBarItemIconsNavigationArrowsColor=warningIconsBuildHammerHandleColor=b06112IconsBuildHammerHeadColor=toolBarItemIconsModeWelcomeActiveColor=successIconsModeEditActiveColor=messageIconsModeDesignActiveColor=warningIconsModeDebugActiveColor=messageIconsModeProjectActiveColor=successIconsModeAnalyzeActiveColor=messageIconsModeHelpActiveColor=warningIconsCodeModelKeywordColor=ff777777IconsCodeModelClassColor=ffc0b550IconsCodeModelStructColor=ff53b053IconsCodeModelFunctionColor=ffd34373IconsCodeModelVariableColor=ff2bbbccIconsCodeModelEnumColor=ffc0b550IconsCodeModelMacroColor=ff476ba0IconsCodeModelAttributeColor=ff316511IconsCodeModelUniformColor=ff994899IconsCodeModelVaryingColor=ffa08833IconsCodeModelOverlayBackgroundColor=normalBackgroundIconsCodeModelOverlayForegroundColor=textInfoBarBackground=shadowBackgroundInfoBarText=textMenuBarEmptyAreaBackgroundColor=shadowBackgroundMenuBarItemBackgroundColor=shadowBackgroundMenuBarItemTextColorDisabled=textDisabledMenuBarItemTextColorNormal=textMenuItemTextColorDisabled=textDisabledMenuItemTextColorNormal=textMiniProjectTargetSelectorBackgroundColor=shadowBackgroundMiniProjectTargetSelectorBorderColor=shadowBackgroundMiniProjectTargetSelectorSummaryBackgroundColor=normalBackgroundMiniProjectTargetSelectorTextColor=fancyBarsNormalTextColorPanelStatusBarBackgroundColor=shadowBackgroundPanelsWidgetSeparatorLineColor=splitterPanelTextColorDark=textPanelTextColorMid=textPanelTextColorLight=textHighlightedProgressBarColorError=errorProgressBarColorFinished=successProgressBarColorNormal=messageProgressBarTitleColor=textProgressBarBackgroundColor=alternateBackgroundSplitterColor=splitterTextColorDisabled=textDisabledTextColorError=errorTextColorHighlight=textHighlightedTextColorHighlightBackground=hoverBackgroundTextColorLink=textColorLinkTextColorLinkVisited=textColorLinkVisitedTextColorNormal=textToggleButtonBackgroundColor=shadowBackgroundToolBarBackgroundColor=shadowBackgroundTreeViewArrowColorNormal=hoverBackgroundTreeViewArrowColorSelected=textOutputPanes_DebugTextColor=textOutputPanes_ErrorMessageTextColor=errorOutputPanes_MessageOutput=messageOutputPanes_NormalMessageTextColor=textOutputPanes_StdErrTextColor=errorOutputPanes_StdOutTextColor=textOutputPanes_WarningMessageTextColor=warningOutputPanes_TestPassTextColor=successOutputPanes_TestFailTextColor=errorOutputPanes_TestXFailTextColor=errorOutputPanes_TestXPassTextColor=messageOutputPanes_TestSkipTextColor=messageOutputPanes_TestWarnTextColor=warningOutputPanes_TestFatalTextColor=errorOutputPanes_TestDebugTextColor=textOutputPaneButtonFlashColor=errorOutputPaneToggleButtonTextColorChecked=fancyBarsNormalTextColorOutputPaneToggleButtonTextColorUnchecked=fancyBarsNormalTextColorDebugger_LogWindow_LogInput=ff56b6c2Debugger_LogWindow_LogStatus=messageDebugger_LogWindow_LogTime=errorDebugger_WatchItem_ValueNormal=textDebugger_WatchItem_ValueInvalid=textDisabledDebugger_WatchItem_ValueChanged=errorDebugger_Breakpoint_TextMarkColor=messageWelcome_TextColor=textWelcome_ForegroundPrimaryColor=textWelcome_ForegroundSecondaryColor=textWelcome_BackgroundColor=normalBackgroundWelcome_ButtonBackgroundColor=normalBackgroundWelcome_DividerColor=splitterWelcome_HoverColor=hoverBackgroundWelcome_LinkColor=textColorLinkWelcome_DisabledLinkColor=textDisabledTimeline_TextColor=textTimeline_BackgroundColor1=normalBackgroundTimeline_BackgroundColor2=shadowBackgroundTimeline_DividerColor=splitterTimeline_HighlightColor=selectedBackgroundTimeline_PanelBackgroundColor=alternateBackgroundTimeline_PanelHeaderColor=normalBackgroundTimeline_HandleColor=ff4b5362Timeline_RangeColor=selectedBackgroundVcsBase_FileStatusUnknown_TextColor=textVcsBase_FileAdded_TextColor=successVcsBase_FileModified_TextColor=warningVcsBase_FileDeleted_TextColor=errorVcsBase_FileRenamed_TextColor=messageVcsBase_FileUnmerged_TextColor=errorBookmarks_TextMarkColor=messageTextEditor_SearchResult_ScrollBarColor=successTextEditor_CurrentLine_ScrollBarColor=messageProjectExplorer_TaskError_TextMarkColor=errorProjectExplorer_TaskWarn_TextMarkColor=warningCodeModel_Error_TextMarkColor=errorCodeModel_Warning_TextMarkColor=warningQmlDesigner_BackgroundColor=normalBackgroundQmlDesigner_HighlightColor=selectedBackgroundQmlDesigner_FormEditorSelectionColor=messageQmlDesigner_FormEditorForegroundColor=normalBackgroundQmlDesigner_BackgroundColorDarkAlternate=shadowBackgroundQmlDesigner_BackgroundColorDarker=splitterQmlDesigner_BorderColor=splitterQmlDesigner_ButtonColor=normalBackgroundQmlDesigner_TabDark=shadowBackgroundQmlDesigner_TabLight=textQmlDesigner_FormeditorBackgroundColor=normalBackgroundQmlDesigner_AlternateBackgroundColor=alternateBackgroundQmlDesigner_ScrollBarHandleColor=ff4b5362PaletteWindow=shadowBackgroundPaletteWindowText=textPaletteBase=normalBackgroundPaletteAlternateBase=alternateBackgroundPaletteButton=shadowBackgroundPaletteBrightText=errorPaletteText=textPaletteButtonText=textPaletteButtonTextDisabled=textDisabledPaletteToolTipBase=hoverBackgroundPaletteHighlight=selectedBackgroundPaletteDark=shadowBackgroundPaletteHighlightedText=selectedBackgroundTextPaletteToolTipText=textPaletteLink=textColorLinkPaletteLinkVisited=textColorLinkVisitedPaletteWindowDisabled=backgroundColorDisabledPaletteWindowTextDisabled=textDisabledPaletteBaseDisabled=backgroundColorDisabledPaletteTextDisabled=textDisabled[Flags]ComboBoxDrawTextShadow=falseDerivePaletteFromTheme=trueDrawIndicatorBranch=trueDrawSearchResultWidgetFrame=falseDrawTargetSelectorBottom=falseDrawToolBarHighlights=falseDrawToolBarBorders=falseApplyThemePaletteGlobally=trueFlatToolBars=trueFlatSideBarIcons=trueFlatProjectsMode=trueFlatMenuBar=trueToolBarIconShadow=trueWindowColorAsBase=trueDarkUserInterface=true[Gradients]DetailsWidgetHeaderGradient\1\color=normalBackgroundDetailsWidgetHeaderGradient\1\pos=1DetailsWidgetHeaderGradient\size=1
如图(7)所示:
图(7) 在Qt的themes目录,创建oneDark.creatortheme文件3.2 启用该主题
打开QtCreator --》点击菜单栏上的[工具] --> 选项 --》 环境 --》Interface --> Theme 选择:oneDark --》Apply,如图(8)所示:
图(8) 启用oneDark主题4 重启Qt Creator
Qt Creator设置在自身的字体、颜色、主题样式之后,需要手动重启一下Qt Creator,即把Qt Creator先关闭后打开,就是重启Qt Creator。
效果如下:
5 Qt Creator字体与主题文件
Qt Creator字体与主题文件: https://pan.baidu.com/s/1xAxDVU4JVbEuLVUvZleijA 提取码:hsst