当前位置:   article > 正文

QTabWidget和QTabBar的外观定制_qtabbar::tab 外圆弧

qtabbar::tab 外圆弧

转自http://developer.qt.nokia.com/doc/qt-4.8/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar

Customizing QTabWidget and QTabBar

For the screenshot above, we need a stylesheet as follows:

  1. QTabWidget::pane { /* The tab widget frame */
  2. border-top: 2px solid #C2C7CB;
  3. }
  4. QTabWidget::tab-bar {
  5. left: 5px; /* move to the right by 5px */
  6. }
  7. /* Style the tab using the tab sub-control. Note that
  8. it reads QTabBar _not_ QTabWidget */
  9. QTabBar::tab {
  10. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  11. stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
  12. stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
  13. border: 2px solid #C4C4C3;
  14. border-bottom-color: #C2C7CB; /* same as the pane color */
  15. border-top-left-radius: 4px;
  16. border-top-right-radius: 4px;
  17. min-width: 8ex;
  18. padding: 2px;
  19. }
  20. QTabBar::tab:selected, QTabBar::tab:hover {
  21. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  22. stop: 0 #fafafa, stop: 0.4 #f4f4f4,
  23. stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
  24. }
  25. QTabBar::tab:selected {
  26. border-color: #9B9B9B;
  27. border-bottom-color: #C2C7CB; /* same as pane color */
  28. }
  29. QTabBar::tab:!selected {
  30. margin-top: 2px; /* make non-selected tabs look smaller */
  31. }

Often we require the tabs to overlap to look like below:

For a tab widget that looks like above, we make use of negative margins. The resulting stylesheet looks like this:

  1. QTabWidget::pane { /* The tab widget frame */
  2. border-top: 2px solid #C2C7CB;
  3. }
  4. QTabWidget::tab-bar {
  5. left: 5px; /* move to the right by 5px */
  6. }
  7. /* Style the tab using the tab sub-control. Note that
  8. it reads QTabBar _not_ QTabWidget */
  9. QTabBar::tab {
  10. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  11. stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
  12. stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
  13. border: 2px solid #C4C4C3;
  14. border-bottom-color: #C2C7CB; /* same as the pane color */
  15. border-top-left-radius: 4px;
  16. border-top-right-radius: 4px;
  17. min-width: 8ex;
  18. padding: 2px;
  19. }
  20. QTabBar::tab:selected, QTabBar::tab:hover {
  21. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  22. stop: 0 #fafafa, stop: 0.4 #f4f4f4,
  23. stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
  24. }
  25. QTabBar::tab:selected {
  26. border-color: #9B9B9B;
  27. border-bottom-color: #C2C7CB; /* same as pane color */
  28. }
  29. QTabBar::tab:!selected {
  30. margin-top: 2px; /* make non-selected tabs look smaller */
  31. }
  32. /* make use of negative margins for overlapping tabs */
  33. QTabBar::tab:selected {
  34. /* expand/overlap to the left and right by 4px */
  35. margin-left: -4px;
  36. margin-right: -4px;
  37. }
  38. QTabBar::tab:first:selected {
  39. margin-left: 0; /* the first selected tab has nothing to overlap with on the left */
  40. }
  41. QTabBar::tab:last:selected {
  42. margin-right: 0; /* the last selected tab has nothing to overlap with on the right */
  43. }
  44. QTabBar::tab:only-one {
  45. margin: 0; /* if there is only one tab, we don't want overlapping margins */
  46. }

To move the tab bar to the center (as below), we require the following stylesheet:

  1. QTabWidget::pane { /* The tab widget frame */
  2. border-top: 2px solid #C2C7CB;
  3. position: absolute;
  4. top: -0.5em;
  5. }
  6. QTabWidget::tab-bar {
  7. alignment: center;
  8. }
  9. /* Style the tab using the tab sub-control. Note that
  10. it reads QTabBar _not_ QTabWidget */
  11. QTabBar::tab {
  12. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  13. stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
  14. stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
  15. border: 2px solid #C4C4C3;
  16. border-bottom-color: #C2C7CB; /* same as the pane color */
  17. border-top-left-radius: 4px;
  18. border-top-right-radius: 4px;
  19. min-width: 8ex;
  20. padding: 2px;
  21. }
  22. QTabBar::tab:selected, QTabBar::tab:hover {
  23. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  24. stop: 0 #fafafa, stop: 0.4 #f4f4f4,
  25. stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
  26. }
  27. QTabBar::tab:selected {
  28. border-color: #9B9B9B;
  29. border-bottom-color: #C2C7CB; /* same as pane color */
  30. }

The tear indicator and the scroll buttons can be further customized as follows:

  1. QTabBar::tear {
  2. image: url(tear_indicator.png);
  3. }
  4. QTabBar::scroller { /* the width of the scroll buttons */
  5. width: 20px;
  6. }
  7. QTabBar QToolButton { /* the scroll buttons are tool buttons */
  8. border-image: url(scrollbutton.png) 2;
  9. border-width: 2px;
  10. }
  11. QTabBar QToolButton::right-arrow { /* the arrow mark in the tool buttons */
  12. image: url(rightarrow.png);
  13. }
  14. QTabBar QToolButton::left-arrow {
  15. image: url(leftarrow.png);
  16. }

Since Qt 4.6 the close button can be customized as follow:

  1. QTabBar::close-button {
  2. image: url(close.png)
  3. subcontrol-position: left;
  4. }
  5. QTabBar::close-button:hover {
  6. image: url(close-hover.png)
  7. }
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号