Skip to content

Commit

Permalink
Fix color buttons disappearing in windows when alpha is set (fix #10187)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and NathanW2 committed Jun 12, 2014
1 parent f1b5838 commit da99331
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/gui/qgscolorbutton.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgscolorbutton.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit da99331

Please sign in to comment.