QtCreator的一些自定义

一、配色方案:
配置方法:工具->选项->文本编辑器->配色方案
如果对这些QtCreator自带的配色方案不满意,则需要手动进行添加
方法:
这些配色方案是以xml文件的形式存在于%QtCreatorDir%\share\qtcreator\styles\中的。
以下是一个vs风格的颜色方案
来自 
http://gurumeditation.org/files/VisualStudio.xml 
  1. <!-- Thanks for visiting http://gurumeditation.org -->
  2. <style-scheme version="1.0" name="VisualStudio">
  3. <style name="AddedLine" foreground="#00aa00"/>
  4. <style name="Comment" foreground="#008000"/>
  5. <style name="CurrentLine" foreground="#000000"/>
  6. <style name="CurrentLineNumber" foreground="#808080" bold="true"/>
  7. <style name="DiffFile" foreground="#000080"/>
  8. <style name="DiffLocation" foreground="#0000ff"/>
  9. <style name="DisabledCode" foreground="#000000" background="#efefef"/>
  10. <style name="Doxygen.Comment" foreground="#000080"/>
  11. <style name="Doxygen.Tag" foreground="#0000ff"/>
  12. <style name="Keyword" foreground="#0000ff"/>
  13. <style name="Label" foreground="#000000"/>
  14. <style name="LineNumber" foreground="#2b91af" background="#ffffff"/>
  15. <style name="Link" foreground="#0000ff"/>
  16. <style name="Number" foreground="#000000"/>
  17. <style name="Occurrences" foreground="#000000" background="#dcdcdc"/>
  18. <style name="Occurrences.Rename" foreground="#000000" background="#ffc8c8"/>
  19. <style name="Occurrences.Unused" foreground="#c0c0c0"/>
  20. <style name="Operator" foreground="#000000"/>
  21. <style name="Parentheses" foreground="#000000" bold="true"/>
  22. <style name="Preprocessor" foreground="#0000ff"/>
  23. <style name="RemovedLine" foreground="#ff0000"/>
  24. <style name="SearchResult" foreground="#000000" background="#ffef0b"/>
  25. <style name="SearchScope" foreground="#000000" background="#ffe8d5"/>
  26. <style name="Selection" foreground="#ffffff" background="#2b6ac5"/>
  27. <style name="String" foreground="#a31515"/>
  28. <style name="Text" foreground="#000000" background="#ffffff"/>
  29. <style name="Type" foreground="#0000ff"/>
  30. <style name="VisualWhitespace" foreground="#c0c0c0"/>
  31. </style-scheme>
上述代码中红色部分即为QtCreator颜色方案下拉菜单中的方案名称
另一个颜色方案
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <style-scheme version="1.0" name="MyDarkTheme">
  3.   <style name="AddedLine" foreground="#359f9f"/>
  4.   <style name="Comment" foreground="#2d9a9e"/>
  5.   <style name="CurrentLine" background="#232323"/>
  6.   <style name="CurrentLineNumber" foreground="#aaaaaa" bold="true"/>
  7.   <style name="DiffFile" foreground="#349e34"/>
  8.   <style name="DiffLocation" foreground="#89892d"/>
  9.   <style name="DisabledCode" foreground="#777777" background="#222222"/>
  10.   <style name="Doxygen.Comment" foreground="#3dbbbb"/>
  11.   <style name="Doxygen.Tag" foreground="#00a0a0"/>
  12.   <style name="Field" foreground="#618f5c"/>
  13.   <style name="Keyword" foreground="#acac39"/>
  14.   <style name="Label" foreground="#bfbf3f"/>
  15.   <style name="LineNumber" foreground="#888888" background="#232323"/>
  16.   <style name="Link" foreground="#0041c4"/>
  17.   <style name="Local" foreground="#696969"/>
  18.   <style name="Number" foreground="#8393c0"/>
  19.   <style name="Occurrences" background="#363636"/>
  20.   <style name="Occurrences.Rename" foreground="#ffaaaa" background="#553636"/>
  21.   <style name="Occurrences.Unused" foreground="#c0c0c0"/>
  22.   <style name="Operator" foreground="#aaaaaa"/>
  23.   <style name="Parentheses" foreground="#ff5555" background="#333333"/>
  24.   <style name="Preprocessor" foreground="#917bbc"/>
  25.   <style name="RemovedLine" foreground="#b43c3c"/>
  26.   <style name="SearchResult" background="#555500"/>
  27.   <style name="SearchScope" background="#222200"/>
  28.   <style name="Selection" foreground="#000000" background="#aaaaaa"/>
  29.   <style name="Static" foreground="#a69829"/>
  30.   <style name="String" foreground="#485abe"/>
  31.   <style name="Text" foreground="#a1a1a1" background="#000000"/>
  32.   <style name="Type" foreground="#317f13"/>
  33.   <style name="VirtualMethod" foreground="#a69174" italic="true"/>
  34.   <style name="VisualWhitespace" foreground="#c0c0c0"/>
  35. </style-scheme>
其中规则并不难,稍加学习理解即可以做出适合自己的颜色方案。

二、代码区外的颜色
上述颜色方案的配置仅影响代码编辑区域,若要对其余区域进行自定义,需要用到Qt中的CSS: QSS
一个可用的配置文件如下

  1. QMainWindow,
  2. QAbstractItemView,
  3. QTreeView::branch,
  4. QTabBar::tab{
  5.     color: #EAEAEA;
  6.     background: #333333;
  7.     font-size: 9pt;
  8. }

  9. QAbstractItemView::item:selected {
  10.     color: #EAEAEA;
  11.     background-color: #151515;
  12. }

  13. QScrollBar {
  14.      border: none;
  15.      background: #494949;
  16.      height: 6px;
  17.      width: 6px;
  18.      margin: 0px;
  19. }

  20. QScrollBar::handle{
  21.      background: #DBDBDB;
  22.      min-width: 20px;
  23.      min-height: 20px;
  24. }

  25. QScrollBar::add-line, QScrollBar::sub-line {
  26.      background: none;
  27.      border: none;
  28. }

  29. QScrollBar::add-page, QScrollBar::sub-page {
  30.      background: none;
  31. }

  32. QTreeView::branch:closed:adjoins-item:has-children {
  33.      background: solid #777777;
  34.      margin: 6px;
  35.      height: 6px;
  36.      width: 6px;
  37.      border-radius: 3px;
  38. }

  39. QTabBar::tab:selected {
  40.      font: bold;
  41.      border-color: #9B9B9B;
  42.      border-bottom-color: #C2C7CB;
  43.  }

  44. QTabBar::tab:!selected {
  45.      margin-top: 2px;
  46.  }

  47. QHeaderView::section {
  48.      background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
  49.                                        stop:0 #616161, stop: 0.5 #505050,
  50.                                        stop: 0.6 #434343, stop:1 #656565);
  51.      color: white;
  52.      padding-left: 4px;
  53.      border: 1px solid #6c6c6c;
  54. }

  55. QToolBar {
  56.      border-style: solid;
  57.      border-style: outset;
  58.      color: #EAEAEA;
  59.      background: #333333;
  60.      font-size: 9pt;
  61. }
将上述内容保存为css文件运行如下命令命令:

  1. qtcreator.exe -stylesheet yourconfig.css
从如下两篇文章中可以获得更多QSS的知识:  Qt Style Sheets Reference Qt Style Sheets Examples  .Qt助手好像带有这两篇文章。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值