QtCreator的一些自定义代码字体和颜色

来源:互联网 发布:易语言钩子注入源码 编辑:程序博客网 时间:2024/05/20 23:37
本文非完全原创,属归纳和总结,发文于此,仅望于人有益
windows平台,仅供参考

一、配色方案:
配置方法:工具->选项->文本编辑器->配色方案
如果对这些QtCreator自带的配色方案不满意,则需要手动进行添加
方法:
这些配色方案是以xml文件的形式存在于%QtCreatorDir%\share\qtcreator\styles\中的。
以下是一个vs风格的颜色方案
来自 
http://gurumeditation.org/index.php/archives/64
http://gurumeditation.org/files/VisualStudio.xml

       <!-- Thanks for visiting http://gurumeditation.org -->    <style-scheme version="1.0" name="VisualStudio">    <style name="AddedLine" foreground="#00aa00"/>    <style name="Comment" foreground="#008000"/>    <style name="CurrentLine" foreground="#000000"/>    <style name="CurrentLineNumber" foreground="#808080" bold="true"/>    <style name="DiffFile" foreground="#000080"/>    <style name="DiffLocation" foreground="#0000ff"/>    <style name="DisabledCode" foreground="#000000" background="#efefef"/>    <style name="Doxygen.Comment" foreground="#000080"/>    <style name="Doxygen.Tag" foreground="#0000ff"/>    <style name="Keyword" foreground="#0000ff"/>    <style name="Label" foreground="#000000"/>    <style name="LineNumber" foreground="#2b91af" background="#ffffff"/>    <style name="Link" foreground="#0000ff"/>    <style name="Number" foreground="#000000"/>    <style name="Occurrences" foreground="#000000" background="#dcdcdc"/>    <style name="Occurrences.Rename" foreground="#000000" background="#ffc8c8"/>    <style name="Occurrences.Unused" foreground="#c0c0c0"/>    <style name="Operator" foreground="#000000"/>    <style name="Parentheses" foreground="#000000" bold="true"/>    <style name="Preprocessor" foreground="#0000ff"/>    <style name="RemovedLine" foreground="#ff0000"/>    <style name="SearchResult" foreground="#000000" background="#ffef0b"/>    <style name="SearchScope" foreground="#000000" background="#ffe8d5"/>    <style name="Selection" foreground="#ffffff" background="#2b6ac5"/>    <style name="String" foreground="#a31515"/>    <style name="Text" foreground="#000000" background="#ffffff"/>    <style name="Type" foreground="#0000ff"/>    <style name="VisualWhitespace" foreground="#c0c0c0"/>    </style-scheme>

上述代码中红色部分即为QtCreator颜色方案下拉菜单中的方案名称
另一个颜色方案
来自http://qt-project.org/forums/viewthread/7680
       <?xml version="1.0" encoding="UTF-8"?>      <style-scheme version="1.0" name="MyDarkTheme">      <style name="AddedLine" foreground="#359f9f"/>      <style name="Comment" foreground="#2d9a9e"/>      <style name="CurrentLine" background="#232323"/>      <style name="CurrentLineNumber" foreground="#aaaaaa" bold="true"/>      <style name="DiffFile" foreground="#349e34"/>      <style name="DiffLocation" foreground="#89892d"/>      <style name="DisabledCode" foreground="#777777" background="#222222"/>      <style name="Doxygen.Comment" foreground="#3dbbbb"/>      <style name="Doxygen.Tag" foreground="#00a0a0"/>      <style name="Field" foreground="#618f5c"/>      <style name="Keyword" foreground="#acac39"/>      <style name="Label" foreground="#bfbf3f"/>      <style name="LineNumber" foreground="#888888" background="#232323"/>      <style name="Link" foreground="#0041c4"/>      <style name="Local" foreground="#696969"/>      <style name="Number" foreground="#8393c0"/>      <style name="Occurrences" background="#363636"/>      <style name="Occurrences.Rename" foreground="#ffaaaa" background="#553636"/>      <style name="Occurrences.Unused" foreground="#c0c0c0"/>      <style name="Operator" foreground="#aaaaaa"/>      <style name="Parentheses" foreground="#ff5555" background="#333333"/>      <style name="Preprocessor" foreground="#917bbc"/>      <style name="RemovedLine" foreground="#b43c3c"/>      <style name="SearchResult" background="#555500"/>      <style name="SearchScope" background="#222200"/>      <style name="Selection" foreground="#000000" background="#aaaaaa"/>      <style name="Static" foreground="#a69829"/>      <style name="String" foreground="#485abe"/>      <style name="Text" foreground="#a1a1a1" background="#000000"/>      <style name="Type" foreground="#317f13"/>      <style name="VirtualMethod" foreground="#a69174" italic="true"/>      <style name="VisualWhitespace" foreground="#c0c0c0"/>    </style-scheme>
其中规则并不难,稍加学习理解即可以做出适合自己的颜色方案。

二、代码区外的颜色
参考自此处http://stackoverflow.com/questions/2244774/qt-creator-color-scheme
上述颜色方案的配置仅影响代码编辑区域,若要对其余区域进行自定义,需要用到Qt中的CSS:QSS
一个可用的配置文件如下

    QMainWindow,    QAbstractItemView,    QTreeView::branch,    QTabBar::tab{        color: #EAEAEA;        background: #333333;        font-size: 9pt;    }    QAbstractItemView::item:selected {        color: #EAEAEA;        background-color: #151515;    }    QScrollBar {         border: none;         background: #494949;         height: 6px;         width: 6px;         margin: 0px;    }    QScrollBar::handle{         background: #DBDBDB;         min-width: 20px;         min-height: 20px;    }    QScrollBar::add-line, QScrollBar::sub-line {         background: none;         border: none;    }    QScrollBar::add-page, QScrollBar::sub-page {         background: none;    }    QTreeView::branch:closed:adjoins-item:has-children {         background: solid #777777;         margin: 6px;         height: 6px;         width: 6px;         border-radius: 3px;    }    QTabBar::tab:selected {         font: bold;         border-color: #9B9B9B;         border-bottom-color: #C2C7CB;     }    QTabBar::tab:!selected {         margin-top: 2px;     }    QHeaderView::section {         background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,                                           stop:0 #616161, stop: 0.5 #505050,                                           stop: 0.6 #434343, stop:1 #656565);         color: white;         padding-left: 4px;         border: 1px solid #6c6c6c;    }    QToolBar {         border-style: solid;         border-style: outset;         color: #EAEAEA;         background: #333333;         font-size: 9pt;    }
将上述内容保存为css文件运行如下命令命令:

qtcreator.exe -stylesheet yourconfig.css

从如上两篇文章中可以获得更多QSS的知识: Qt Style Sheets ReferenceQt Style Sheets Examples .Qt助手好像带有这两篇文章。