Results 1 to 5 of 5

Thread: Custom Style based on Cleanlooks

  1. #1
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Custom Style based on Cleanlooks

    I've made a custom style based on the existing cleanlooks style. I've got almoast everything the way I want, only I can not change the scroll bar. At least not the way I would like it.

    I have to scrollbar images, one for vertical and one for horizontal scrollbar. But when I try to add them the whole scroll bar get's that image instead of just the scrollbar slider.

    This is the code where I drawComplexControl():
    Qt Code:
    1. void mediaArchiverStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex * option, QPainter * painter, const QWidget * widget) const
    2. {
    3. switch (control) {
    4. case CC_ScrollBar:
    5. {
    6. int delta = (option->state & State_MouseOver) ? 64 : 0;
    7. QColor slightlyOpaqueBlack(100, 100, 100, 63);
    8. QColor semiTransparentWhite(255, 255, 255, 127 + delta);
    9. QColor semiTransparentBlack(10, 10, 10, 127 - delta);
    10.  
    11. int x, y, width, height;
    12. option->rect.getRect(&x, &y, &width, &height);
    13.  
    14. QPainterPath roundRect = roundRectPath(option->rect);
    15. int radius = qMin(width, height) / 2;
    16.  
    17. QBrush brush;
    18. bool darker;
    19.  
    20. const QStyleOptionSlider *sliderOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
    21. if (sliderOption) {
    22. if (sliderOption->orientation == Qt::Vertical)
    23. brush = option->palette.light();
    24. else
    25. brush = option->palette.midlight();
    26. darker = false;
    27. }
    28.  
    29. QStyleOptionSlider mySliderOption;
    30. if (sliderOption) {
    31. mySliderOption = *sliderOption;
    32. if (mySliderOption.palette.currentColorGroup() != QPalette::Disabled) {
    33. if (mySliderOption.state & (State_Enabled)) {
    34. mySliderOption.palette.setBrush(QPalette::ButtonText,
    35. mySliderOption.palette.brightText());
    36. }
    37. }
    38. }
    39. QCleanlooksStyle::drawComplexControl(control, &mySliderOption, painter, widget);
    40.  
    41. painter->save();
    42. painter->setRenderHint(QPainter::Antialiasing, true);
    43. painter->fillPath(roundRect, brush);
    44. if (darker)
    45. painter->fillPath(roundRect, slightlyOpaqueBlack);
    46.  
    47. int penWidth;
    48. if (radius < 10)
    49. penWidth = 3;
    50. else if (radius < 20)
    51. penWidth = 5;
    52. else
    53. penWidth = 7;
    54.  
    55. QPen topPen(semiTransparentWhite, penWidth);
    56. QPen bottomPen(semiTransparentBlack, penWidth);
    57.  
    58. if (option->state & (State_Enabled))
    59. qSwap(topPen, bottomPen);
    60.  
    61. int x1 = x;
    62. int x2 = x + radius;
    63. int x3 = x + width - radius;
    64. int x4 = x + width;
    65.  
    66. if (option->direction == Qt::RightToLeft) {
    67. qSwap(x1, x4);
    68. qSwap(x2, x3);
    69. }
    70.  
    71. QPolygon topHalf;
    72. topHalf << QPoint(x1, y)
    73. << QPoint(x4, y)
    74. << QPoint(x3, y + radius)
    75. << QPoint(x2, y + height - radius)
    76. << QPoint(x1, y + height);
    77.  
    78. painter->setClipPath(roundRect);
    79. painter->setClipRegion(topHalf, Qt::IntersectClip);
    80. painter->setPen(topPen);
    81. painter->drawPath(roundRect);
    82.  
    83. QPolygon bottomHalf = topHalf;
    84. bottomHalf[0] = QPoint(x4, y + height);
    85.  
    86. painter->setClipPath(roundRect);
    87. painter->setClipRegion(bottomHalf, Qt::IntersectClip);
    88. painter->setPen(bottomPen);
    89. painter->drawPath(roundRect);
    90.  
    91. painter->setPen(option->palette.foreground().color());
    92. painter->setClipping(false);
    93. painter->drawPath(roundRect);
    94.  
    95. painter->restore();
    96. }
    97. break;
    98. default:
    99. QCleanlooksStyle::drawComplexControl(control, option, painter, widget);
    100. }
    101. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Style based on Cleanlooks

    I think you should call drawControl() and you should draw the scrollbar slider from within there.

  3. #3
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Custom Style based on Cleanlooks

    I tried that to.
    But CE_ScrollBarSlider never gets "triggered".
    I put a qDebug() in it and start the app but nothing appears on the console.

    Funy part is, that if I inherit from QMotifStyle class the srollbar gets styled well, only the images are a bit mixed up. But I don't like motif very much and I would like to do it with cleanlooks.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Style based on Cleanlooks

    You probably have to call it yourself from within drawComplexControl.

  5. #5
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Custom Style based on Cleanlooks

    You mean calling drawControl and pass it the CE?
    Doesn't do much good.
    It just changes the whole scrollbar, again, instead of the slider.

Similar Threads

  1. Custom Style and Qt Designer 3
    By iukpo in forum Qt Tools
    Replies: 1
    Last Post: 23rd January 2007, 00:39
  2. Custom Style
    By Dusdan in forum Qt Tools
    Replies: 8
    Last Post: 1st September 2006, 22:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.