Skip to content

Commit da99331

Browse files
nyalldawsonNathanW2
authored andcommittedJun 12, 2014
Fix color buttons disappearing in windows when alpha is set (fix #10187)
1 parent f1b5838 commit da99331

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
 

‎src/gui/qgscolorbutton.cpp

100644100755
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727
#include <QClipboard>
2828
#include <QDrag>
2929

30+
#ifdef Q_OS_WIN
31+
#include <windows.h>
32+
QString QgsColorButton::fullPath( const QString &path )
33+
{
34+
TCHAR buf[MAX_PATH];
35+
int len = GetLongPathName( path.toUtf8().constData(), buf, MAX_PATH );
36+
37+
if ( len == 0 || len > MAX_PATH )
38+
{
39+
QgsDebugMsg( QString( "GetLongPathName('%1') failed with %2: %3" )
40+
.arg( path ).arg( len ).arg( GetLastError() ) );
41+
return path;
42+
}
43+
44+
QString res = QString::fromUtf8( buf );
45+
return res;
46+
}
47+
#endif
48+
3049
/*!
3150
\class QgsColorButton
3251
@@ -387,11 +406,15 @@ void QgsColorButton::setButtonBackground()
387406
mTempPNG.close();
388407
}
389408

390-
bkgrd = QString( " background-image: url(%1);" ).arg( mTempPNG.fileName() );
409+
QString bgFileName = mTempPNG.fileName();
410+
#ifdef Q_OS_WIN
411+
//on windows, mTempPNG will use a shortened path for the temporary folder name
412+
//this does not work with stylesheets, resulting in the whole button disappearing (#10187)
413+
bgFileName = fullPath( bgFileName );
414+
#endif
415+
bkgrd = QString( " background-image: url(%1);" ).arg( bgFileName );
391416
}
392417

393-
//QgsDebugMsg( QString( "%1" ).arg( bkgrd ) );
394-
395418
// TODO: get OS-style focus color and switch border to that color when button in focus
396419
setStyleSheet( QString( "QgsColorButton{"
397420
" %1"

‎src/gui/qgscolorbutton.h

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ class GUI_EXPORT QgsColorButton: public QPushButton
191191
*/
192192
bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
193193

194+
#ifdef Q_OS_WIN
195+
/**
196+
* Expands a shortened Windows path to its full path name.
197+
* @returns full path name.
198+
* @param path a (possibly) shortened Windows path
199+
* @note added in 2.3
200+
*/
201+
QString fullPath( const QString &path );
202+
#endif
203+
194204
private slots:
195205
void onButtonClicked();
196206

0 commit comments

Comments
 (0)
Please sign in to comment.