Skip to content
Permalink
Browse files
Fix color buttons disappearing in windows when alpha is set (fix #10187)
  • Loading branch information
nyalldawson authored and NathanW2 committed Jun 12, 2014
1 parent f1b5838 commit da99331d8581630228e40d5f3533f0cf0262f6cb
Showing with 36 additions and 3 deletions.
  1. +26 −3 src/gui/qgscolorbutton.cpp
  2. +10 −0 src/gui/qgscolorbutton.h
29 src/gui/qgscolorbutton.cpp 100644 → 100755
@@ -27,6 +27,25 @@
#include <QClipboard>
#include <QDrag>

#ifdef Q_OS_WIN
#include <windows.h>
QString QgsColorButton::fullPath( const QString &path )
{
TCHAR buf[MAX_PATH];
int len = GetLongPathName( path.toUtf8().constData(), buf, MAX_PATH );

if ( len == 0 || len > MAX_PATH )
{
QgsDebugMsg( QString( "GetLongPathName('%1') failed with %2: %3" )
.arg( path ).arg( len ).arg( GetLastError() ) );
return path;
}

QString res = QString::fromUtf8( buf );
return res;
}
#endif

/*!
\class QgsColorButton
@@ -387,11 +406,15 @@ void QgsColorButton::setButtonBackground()
mTempPNG.close();
}

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

//QgsDebugMsg( QString( "%1" ).arg( bkgrd ) );

// TODO: get OS-style focus color and switch border to that color when button in focus
setStyleSheet( QString( "QgsColorButton{"
" %1"
10 src/gui/qgscolorbutton.h 100644 → 100755
@@ -191,6 +191,16 @@ class GUI_EXPORT QgsColorButton: public QPushButton
*/
bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );

#ifdef Q_OS_WIN
/**
* Expands a shortened Windows path to its full path name.
* @returns full path name.
* @param path a (possibly) shortened Windows path
* @note added in 2.3
*/
QString fullPath( const QString &path );
#endif

private slots:
void onButtonClicked();

0 comments on commit da99331

Please sign in to comment.