Commit acc764552c552df31719af561e285886085371e9

  • avatar
  • Martin Smith <msmith @trol…ech.com>
  • Tue Jun 16 11:17:06 GMT 2009
doc: Added info on two ways to customize the style.
doc/src/snippets/code/src_gui_qproxystyle.cpp
(30 / 0)
  
1313};
1414
1515//! [0]
16
17//! [1]
18#include "textedit.h"
19#include <QApplication>
20#include <QProxyStyle>
21
22class MyProxyStyle : public QProxyStyle
23{
24 public:
25 int styleHint(StyleHint hint, const QStyleOption *option = 0,
26 const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const
27 {
28 if (hint == QStyle::SH_UnderlineShortcut)
29 return 0;
30 return QProxyStyle::styleHint(hint, option, widget, returnData);
31 }
32};
33
34int main(int argc, char **argv)
35{
36 Q_INIT_RESOURCE(textedit);
37
38 QApplication a(argc, argv);
39 a.setStyle(new MyProxyStyle);
40 TextEdit mw;
41 mw.resize(700, 800);
42 mw.show();
43 //...
44}
45//! [1]
src/gui/styles/qproxystyle.cpp
(1 / 1)
  
6565 Below is an example that overrides the shortcut underline
6666 behavior on all platforms:
6767
68 \snippet doc/src/snippets/code/src_gui_qproxystyle.cpp 0
68 \snippet doc/src/snippets/code/src_gui_qproxystyle.cpp 1
6969
7070 Warning: Although Qt's internal styles should respect this hint,
7171 there is no guarantee that it will work for all styles. It would
src/gui/styles/qstyle.cpp
(18 / 9)
  
168168
169169 \section1 Creating a Custom Style
170170
171 If you want to design a custom look and feel for your application,
172 the first step is to pick one of the styles provided with Qt to
173 build your custom style from. The choice will depend on which
174 existing style resembles your style the most. The most general
175 class that you can use as base is QCommonStyle (and not QStyle).
176 This is because Qt requires its styles to be \l{QCommonStyle}s.
171 You can create a custom look and feel for your application by
172 creating a custom style. There are two approaches to creating a
173 custom style. In the static approach, you either choose an
174 existing QStyle class, subclass it, and reimplement virtual
175 functions to provide the custom behavior, or you create an entire
176 QStyle class from scratch. In the dynamic approach, you modify the
177 behavior of your system style at runtime. The static approach is
178 described below. The dynamic approach is described in QProxyStyle.
177179
180 The first step in the static approach is to pick one of the styles
181 provided by Qt from which you will build your custom style. Your
182 choice of QStyle class will depend on which style resembles your
183 desired style the most. The most general class that you can use as
184 a base is QCommonStyle (not QStyle). This is because Qt requires
185 its styles to be \l{QCommonStyle}s.
186
178187 Depending on which parts of the base style you want to change,
179188 you must reimplement the functions that are used to draw those
180189 parts of the interface. To illustrate this, we will modify the
231231 \section1 Using a Custom Style
232232
233233 There are several ways of using a custom style in a Qt
234 application. The simplest way is call the
234 application. The simplest way is to pass the custom style to the
235235 QApplication::setStyle() static function before creating the
236236 QApplication object:
237237
241241 it before the constructor, you ensure that the user's preference,
242242 set using the \c -style command-line option, is respected.
243243
244 You may want to make your style available for use in other
245 applications, some of which may not be yours and are not available for
244 You may want to make your custom style available for use in other
245 applications, which may not be yours and hence not available for
246246 you to recompile. The Qt Plugin system makes it possible to create
247247 styles as plugins. Styles created as plugins are loaded as shared
248248 objects at runtime by Qt itself. Please refer to the \link

Comments

Add a new comment:

Login or create an account to post a comment

Add your comment