From 1bcfada9f04bd20a7a64d448fbf60c0f0820ed09 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 30 Dec 2020 13:55:27 +0100 Subject: QStyle: add name() to return the name of the style Currently there is no way to get the name of the current style to e.g. create a QProxyStyle for a specific widget only. Therefore add QStyle::name() so QProxyStyle(const QString &) can be called without hard-coding the style name. Remove an unused doc snippet as drive-by. Fixes: QTBUG-8004 Change-Id: I466c5e870a5392b238365bdc930f6a2ecee50cdb Reviewed-by: Richard Moe Gustavsen --- .../doc/snippets/code/src_gui_qproxystyle.cpp | 24 ++++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/widgets/doc') diff --git a/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp b/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp index 98dc0ff55b..636a0f52a8 100644 --- a/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp +++ b/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp @@ -48,22 +48,6 @@ ** ****************************************************************************/ -//! [0] -class MyProxyStyle : public QProxyStyle -{ -public: - - int styleHint(StyleHint hint, const QStyleOption *option = nullptr, - const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override - { - if (hint == QStyle::SH_UnderlineShortcut) - return 1; - return QProxyStyle::styleHint(hint, option, widget, returnData); - } -}; - -//! [0] - //! [1] #include "textedit.h" #include @@ -93,3 +77,11 @@ int main(int argc, char **argv) //... } //! [1] + +//! [2] +... +auto proxy = new MyProxyStyle(QApplication::style()->name()); +proxy->setParent(widget); // take ownership to avoid memleak +widget->setStyle(proxy); +... +//! [2] -- cgit v1.2.3