Skip to content

Commit ecff6a9

Browse files
author
morb_au
committed
Real fix for trac ticket #140, but not covering all instances of that bug yet.
Buttons where the background color is meaningful are now rendered in classic Windows style in the Project Properties and Options menus. (Windows XP style only has bitmaps for button backgrounds.) This bug also occurs on (at least) the vector properties dialog, and fixes for that will be committed later. git-svn-id: http://svn.osgeo.org/qgis/trunk@5871 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d12fb0e commit ecff6a9

File tree

4 files changed

+75
-37
lines changed

4 files changed

+75
-37
lines changed

src/gui/qgsoptions.cpp

+20-14
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
#include "qgisapp.h"
2323
#include "qgslayerprojectionselector.h"
2424
#include "qgsspatialrefsys.h"
25+
2526
#include <QFileDialog>
2627
#include <QSettings>
2728
#include <QColorDialog>
29+
2830
#include <cassert>
2931
#include <iostream>
3032
#include <sqlite3.h>
33+
34+
3135
/**
3236
* \class QgsOptions - Set user options and preferences
3337
* Constructor
@@ -113,21 +117,25 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
113117
int myBlue = settings.value("/qgis/default_selection_color_blue",0).toInt();
114118
// old Qt3 idiom
115119
// pbnSelectionColour->setPaletteBackgroundColor(QColor(myRed,myGreen,myBlue));
116-
// new Qt4 idiom
117-
QPalette palSelectionColour = pbnSelectionColour->palette();
118-
palSelectionColour.setColor( QPalette::Window, QColor(myRed,myGreen,myBlue) );
119-
pbnSelectionColour->setPalette(palSelectionColour);
120+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
121+
#ifdef Q_WS_WIN
122+
// Coloured buttons do not work under the Windows XP style - use plain Windows instead
123+
pbnSelectionColour->setStyle(&mWindowsStyle);
124+
#endif
125+
pbnSelectionColour->setPalette( QColor(myRed,myGreen,myBlue) );
120126

121127
//set the default color for canvas background
122128
myRed = settings.value("/qgis/default_canvas_color_red",255).toInt();
123129
myGreen = settings.value("/qgis/default_canvas_color_green",255).toInt();
124130
myBlue = settings.value("/qgis/default_canvas_color_blue",255).toInt();
125131
// old Qt3 idiom
126132
// pbnCanvasColor->setPaletteBackgroundColor(QColor(myRed,myGreen,myBlue));
127-
// new Qt4 idiom
128-
QPalette palCanvasColor = pbnCanvasColor->palette();
129-
palCanvasColor.setColor( QPalette::Window, QColor(myRed,myGreen,myBlue) );
130-
pbnCanvasColor->setPalette(palCanvasColor);
133+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
134+
#ifdef Q_WS_WIN
135+
// Coloured buttons do not work under the Windows XP style - use plain Windows instead
136+
pbnCanvasColor->setStyle(&mWindowsStyle);
137+
#endif
138+
pbnCanvasColor->setPalette( QColor(myRed,myGreen,myBlue) );
131139

132140
capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());
133141
}
@@ -146,9 +154,8 @@ void QgsOptions::on_pbnSelectionColour_clicked()
146154
{
147155
// old Qt3 idiom
148156
// pbnSelectionColour->setPaletteBackgroundColor(color);
149-
// new Qt4 idiom
150-
palSelectionColour.setColor( QPalette::Window, color );
151-
pbnSelectionColour->setPalette(palSelectionColour);
157+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
158+
pbnSelectionColour->setPalette(color);
152159
}
153160
}
154161

@@ -163,9 +170,8 @@ void QgsOptions::on_pbnCanvasColor_clicked()
163170
{
164171
// old Qt3 idiom
165172
// pbnCanvasColor->setPaletteBackgroundColor(color);
166-
// new Qt4 idiom
167-
palCanvasColor.setColor( QPalette::Window, color );
168-
pbnCanvasColor->setPalette(palCanvasColor);
173+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
174+
pbnCanvasColor->setPalette(color);
169175
}
170176
}
171177
void QgsOptions::themeChanged(const QString &newThemeName)

src/gui/qgsoptions.h

+15
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
/* $Id$ */
1919
#ifndef QGSOPTIONS_H
2020
#define QGSOPTIONS_H
21+
2122
#include "ui_qgsoptionsbase.h"
2223
#include "qgisgui.h"
24+
25+
#ifdef Q_WS_WIN
26+
#include <QWindowsStyle>
27+
#endif
28+
29+
30+
2331
/**
2432
* \class QgsOptions
2533
* \brief Set user options and preferences
@@ -79,8 +87,15 @@ class QgsOptions :public QDialog, private Ui::QgsOptionsBase
7987
private:
8088
//! Pointer to our parent
8189
QWidget *qparent;
90+
8291
//!Global default projection used for new layers added that have no projection
8392
long mGlobalSRSID;
93+
94+
#ifdef Q_WS_WIN
95+
//! Holds the classic Windows style that is used to render buttons with a background color
96+
QWindowsStyle mWindowsStyle;
97+
#endif
98+
8499
};
85100

86101
#endif // #ifndef QGSOPTIONS_H

src/gui/qgsprojectproperties.cpp

+25-21
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@
108108
QColor myColour = QColor(myRedInt,myGreenInt,myBlueInt);
109109
// old Qt3 idiom
110110
// pbnDigitisedLineColour->setPaletteBackgroundColor (myColour);
111-
// new Qt4 idiom
112-
QPalette palDigitisedLineColour = pbnDigitisedLineColour->palette();
113-
palDigitisedLineColour.setColor( QPalette::Window, myColour );
114-
pbnDigitisedLineColour->setPalette(palDigitisedLineColour);
111+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
112+
#ifdef Q_WS_WIN
113+
// Coloured buttons do not work under the Windows XP style - use plain Windows instead
114+
pbnDigitisedLineColour->setStyle(&mWindowsStyle);
115+
#endif
116+
pbnDigitisedLineColour->setPalette(myColour);
115117

116118

117119
//get the colour selections and set the button colour accordingly
@@ -121,10 +123,12 @@
121123
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
122124
// old Qt3 idiom
123125
// pbnSelectionColour->setPaletteBackgroundColor (myColour);
124-
// new Qt4 idiom
125-
QPalette palSelectionColour = pbnSelectionColour->palette();
126-
palSelectionColour.setColor( QPalette::Window, myColour );
127-
pbnSelectionColour->setPalette(palSelectionColour);
126+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
127+
#ifdef Q_WS_WIN
128+
// Coloured buttons do not work under the Windows XP style - use plain Windows instead
129+
pbnSelectionColour->setStyle(&mWindowsStyle);
130+
#endif
131+
pbnSelectionColour->setPalette(myColour);
128132

129133
//get the colour for map canvas background and set button colour accordingly (default white)
130134
myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
@@ -133,10 +137,12 @@
133137
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
134138
// old Qt3 idiom
135139
// pbnCanvasColor->setPaletteBackgroundColor (myColour);
136-
// new Qt4 idiom
137-
QPalette palCanvasColor = pbnCanvasColor->palette();
138-
palCanvasColor.setColor( QPalette::Window, myColour );
139-
pbnCanvasColor->setPalette(palCanvasColor);
140+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
141+
#ifdef Q_WS_WIN
142+
// Coloured buttons do not work under the Windows XP style - use plain Windows instead
143+
pbnCanvasColor->setStyle(&mWindowsStyle);
144+
#endif
145+
pbnCanvasColor->setPalette(myColour);
140146
}
141147

142148
QgsProjectProperties::~QgsProjectProperties()
@@ -339,9 +345,9 @@ void QgsProjectProperties::on_pbnDigitisedLineColour_clicked()
339345
{
340346
// old Qt3 idiom
341347
// pbnDigitisedLineColour->setPaletteBackgroundColor(color);
342-
// new Qt4 idiom
343-
palDigitisedLineColour.setColor( QPalette::Window, color );
344-
pbnDigitisedLineColour->setPalette(palDigitisedLineColour);
348+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
349+
pbnDigitisedLineColour->setPalette(color);
350+
345351
}
346352
}
347353

@@ -356,9 +362,8 @@ void QgsProjectProperties::on_pbnSelectionColour_clicked()
356362
{
357363
// old Qt3 idiom
358364
// pbnSelectionColour->setPaletteBackgroundColor(color);
359-
// new Qt4 idiom
360-
palSelectionColour.setColor( QPalette::Window, color );
361-
pbnSelectionColour->setPalette(palSelectionColour);
365+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
366+
pbnSelectionColour->setPalette(color);
362367
}
363368
}
364369

@@ -373,9 +378,8 @@ void QgsProjectProperties::on_pbnCanvasColor_clicked()
373378
{
374379
// old Qt3 idiom
375380
// pbnCanvasColor->setPaletteBackgroundColor(color);
376-
// new Qt4 idiom
377-
palCanvasColor.setColor( QPalette::Window, color );
378-
pbnCanvasColor->setPalette(palCanvasColor);
381+
// new Qt4 idiom - see http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00270-0.html for reasoning
382+
pbnCanvasColor->setPalette(color);
379383
}
380384
}
381385
void QgsProjectProperties::on_pbnHelp_clicked()

src/gui/qgsprojectproperties.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
#include "ui_qgsprojectpropertiesbase.h"
2222
#include "qgis.h"
2323
#include "qgisgui.h"
24-
class QColor;
24+
25+
#ifdef Q_WS_WIN
26+
#include <QWindowsStyle>
27+
#endif
28+
29+
class QColor;
2530

2631
/*! Dialog to set project level properties
2732
@@ -112,6 +117,14 @@ public slots:
112117
void refresh();
113118
//! notification of when on the fly projections are enabled / disabled
114119
void projectionEnabled(bool);
120+
115121
private:
116-
static const int context_id = 361087368;
122+
static const int context_id = 361087368;
123+
124+
#ifdef Q_WS_WIN
125+
//! Holds the classic Windows style that is used to render buttons with a background color
126+
QWindowsStyle mWindowsStyle;
127+
#endif
128+
129+
117130
};

0 commit comments

Comments
 (0)