Académique Documents
Professionnel Documents
Culture Documents
© Trolltech 2007
About me
Me
• Girish Ramakrishnan
• Software Developer + Release manager
Qt Development
• Qt Style Sheet architect
• MinGW platform boss
• Auto completion framework
• Desktop integration
• Part of widget team (message box, label)
FOSS
• KDocker (kdocker.sourceforge.net)
• GUC (guc.mozdev.org)
2 © Trolltech 2007
History
QStyle
• Excellent flexible API. Used by Qt itself
• “Compile, test, compile test” cycle
• QStyle completely shuts off graphics designers
3 © Trolltech 2007
Introducing Qt Style Sheets
4 © Trolltech 2007
What are Style Sheets?
“Style strings”
• Similar to CSS in concept and syntax
• Adapted to the world of widgets
Interactive UI development
• Designer friendly. Compile free
5 © Trolltech 2007
Style Sheet Syntax
A Style Rule
QPushButton – Selector
{ color: red } - Declaration
color – attribute/property
6 © Trolltech 2007
Style Sheet Syntax
QPushButton, QCheckBox {
background-color: magenta;
}
QRadioButton, QCheckBox {
spacing: 8px;
color: gray;
}
7 © Trolltech 2007
Selectors
8 © Trolltech 2007
Pseudo States
9 © Trolltech 2007
The Box Model
10 © Trolltech 2007
Qt Style Sheet Box Model Attributes
margin
border
• border-width
• border-style
• border-color
padding
min-width, min-height
• width and height refer to contents rect
width, height not supported
11 © Trolltech 2007
Background properties
background
• background-image
• background-repeat
• background-position
• background-clip, background-origin
• background-attachment
setting background does not scale!
• Why?
12 © Trolltech 2007
Scalable style sheet
Use gradients
border-radius to provide rounded corners
13 © Trolltech 2007
Border Image
14 © Trolltech 2007
Border Image
15 © Trolltech 2007
Border Image
16 © Trolltech 2007
Border Image
17 © Trolltech 2007
Border Image
border-image: url(btn.png) 5 5 5 5
stretch stretch;
18 © Trolltech 2007
Border Image
border-image: url(btn.png) 5 5 5 5
stretch stretch;
19 © Trolltech 2007
Border Image
border-image: url(btn.png) 5 5 5 5
stretch stretch;
20 © Trolltech 2007
Rendering Model
21 © Trolltech 2007
Rendering Model
22 © Trolltech 2007
Setting the style sheet
QWidget::setStyleSheet()
QApplication::setStyleSheet()
23 © Trolltech 2007
Sub controls
24 © Trolltech 2007
Sub controls
QPushButton::menu-indicator:hover {
border: 2px solid red;
image: url(indicator_hover.png)
}
25 © Trolltech 2007
Sub controls (Geometry)
Size
• width, height
• width and height of the element's content
26 © Trolltech 2007
Rendering Model
27 © Trolltech 2007
Sub control positioning
subcontrol-origin
• The origin rect in the parent's box model
subcontrol-position
• The alignment within the above rect
QPushButton::menu-indicator {
subcontrol-origin: content;
subcontrol-position: right center;
image: url(menu.png);
}
28 © Trolltech 2007
Sub control positioning
29 © Trolltech 2007
Positioning Modes
30 © Trolltech 2007
Relative Positioning
31 © Trolltech 2007
Relative Positioning
32 © Trolltech 2007
Absolute Positioning
Absolute Positioning
• Use top, left, right, bottom to define absolute positions within
the origin rectangle
QPushButton::menu-indicator {
subcontrol-origin: content;
subcontrol-position: right center;
image: url(menu.png);
position: absolute;
width: 20px;
top: 5px; right: 2px; bottom: 5px;
}
33 © Trolltech 2007
Absolute Positioning
34 © Trolltech 2007
Advanced features
35 © Trolltech 2007
Negative Margins
36 © Trolltech 2007
Qt 4.3's well kept secret
•Demo
37 © Trolltech 2007
Future direction
38 © Trolltech 2007
Qt Style Sheets and KDE
39 © Trolltech 2007
More information
Labs
• http://labs.trolltech.com/blogs/
•
Email
• Girish Ramakrishnan (ramakrishnan.girish@trolltech.com)
• Jens Bache Wiig (jbache@trolltech.com)
40 © Trolltech 2007