From a4c7340b73fb93813b74001301b274b42990a896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 29 Nov 2012 08:08:43 +0100 Subject: Make Mac style not crash on null styleObject. We generally expect styleObject to be set during style draw calls but this isn't always done, especially legacy code outside Qt (for example in Qt creator). Create a temporary stand-in QObject. This will disable scroll bar animations. Change-Id: I781967fe28f68f5952b368cd56be980b9e270ecd Reviewed-by: J-P Nurmi --- src/widgets/styles/qmacstyle_mac.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/widgets/styles/qmacstyle_mac.mm') diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index cbc58d1b5d..21b4f57525 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -4907,6 +4907,16 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 if (cc == CC_ScrollBar && proxy()->styleHint(SH_ScrollBar_Transient)) { QObject *styleObject = opt->styleObject; + + // Qt generally excepts styleObject to be set during draw calls, but + // this is not always done. Create a temprary object in that case to + // prevent crashing. This will disable scroll bar animations. + bool deleteStyleObject = false; + if (!styleObject) { + deleteStyleObject = true; + styleObject = new QObject; + } + int oldPos = styleObject->property("_q_stylepos").toInt(); int oldMin = styleObject->property("_q_stylemin").toInt(); int oldMax = styleObject->property("_q_stylemax").toInt(); @@ -5040,6 +5050,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex [NSGraphicsContext restoreGraphicsState]; CGContextRestoreGState(cg); + + if (deleteStyleObject) { + delete styleObject; + } } else #endif { -- cgit v1.2.3