Commit acc764552c552df31719af561e285886085371e9
- Diff rendering mode:
- inline
- side by side
doc/src/snippets/code/src_gui_qproxystyle.cpp
(30 / 0)
|   | |||
| 13 | 13 | }; | |
| 14 | 14 | ||
| 15 | 15 | //! [0] | |
| 16 | |||
| 17 | //! [1] | ||
| 18 | #include "textedit.h" | ||
| 19 | #include <QApplication> | ||
| 20 | #include <QProxyStyle> | ||
| 21 | |||
| 22 | class 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 | |||
| 34 | int 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)
|   | |||
| 65 | 65 | Below is an example that overrides the shortcut underline | |
| 66 | 66 | behavior on all platforms: | |
| 67 | 67 | ||
| 68 | \snippet doc/src/snippets/code/src_gui_qproxystyle.cpp 0 | ||
| 68 | \snippet doc/src/snippets/code/src_gui_qproxystyle.cpp 1 | ||
| 69 | 69 | ||
| 70 | 70 | Warning: Although Qt's internal styles should respect this hint, | |
| 71 | 71 | there is no guarantee that it will work for all styles. It would |
src/gui/styles/qstyle.cpp
(18 / 9)
|   | |||
| 168 | 168 | ||
| 169 | 169 | \section1 Creating a Custom Style | |
| 170 | 170 | ||
| 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. | ||
| 177 | 179 | ||
| 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 | |||
| 178 | 187 | Depending on which parts of the base style you want to change, | |
| 179 | 188 | you must reimplement the functions that are used to draw those | |
| 180 | 189 | parts of the interface. To illustrate this, we will modify the | |
| … | … | ||
| 231 | 231 | \section1 Using a Custom Style | |
| 232 | 232 | ||
| 233 | 233 | 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 | ||
| 235 | 235 | QApplication::setStyle() static function before creating the | |
| 236 | 236 | QApplication object: | |
| 237 | 237 | ||
| … | … | ||
| 241 | 241 | it before the constructor, you ensure that the user's preference, | |
| 242 | 242 | set using the \c -style command-line option, is respected. | |
| 243 | 243 | ||
| 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 | ||
| 246 | 246 | you to recompile. The Qt Plugin system makes it possible to create | |
| 247 | 247 | styles as plugins. Styles created as plugins are loaded as shared | |
| 248 | 248 | 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
Please log in to comment

