Skip to content

Commit 52e80e9

Browse files
author
morb_au
committed
Potential fix for bug in trac ticket #140.
The Qt3 idiom QToolButton::setPaletteBackgroundColor() has been replaced with a Qt4 idiom of extracting the QPalette from the QToolButton, changing the color in the Window ColorRole, then adding the QPalette back in again. Only the QGIS Options and Project Properties dialogs have been converted. If this change fixes the bug in Windows (which I don't have access to a compiler for), then this idiom should be propagated to all instances of setPaletteBackgroundColor (e.g. vector symbology dialog). git-svn-id: http://svn.osgeo.org/qgis/trunk@5696 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 38dddd4 commit 52e80e9

File tree

2 files changed

+114
-25
lines changed

2 files changed

+114
-25
lines changed

src/gui/qgsoptions.cpp

+52-13
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
7777
//! @todo changes this control name in gui to txtGlobalProjString
7878
QString myProjString = QgsSpatialRefSys::getProj4FromSrsId(mGlobalSRSID);
7979
txtGlobalWKT->setText(myProjString);
80-
80+
8181
// populate combo box with ellipsoids
8282
getEllipsoidList();
8383
QString myEllipsoidId = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
@@ -94,25 +94,40 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
9494
cmbTheme->insertItem(myDirList[i]);
9595
}
9696
}
97+
9798
// set the theme combo
9899
cmbTheme->setCurrentText(settings.readEntry("/Themes","default"));
99-
//set teh state of the checkboxes
100+
101+
//set the state of the checkboxes
100102
chkAntiAliasing->setChecked(settings.value("/qgis/enable_anti_aliasing",false).toBool());
103+
101104
// Slightly awkard here at the settings value is true to use QImage,
102105
// but the checkbox is true to use QPixmap
103106
chkUseQPixmap->setChecked(!(settings.value("/qgis/use_qimage_to_render", true).toBool()));
104107
chkAddedVisibility->setChecked(settings.value("/qgis/new_layers_visible",true).toBool());
105108
cbxHideSplash->setChecked(settings.value("/qgis/hideSplash",false).toBool());
109+
106110
//set the colour for selections
107111
int myRed = settings.value("/qgis/default_selection_color_red",255).toInt();
108112
int myGreen = settings.value("/qgis/default_selection_color_green",255).toInt();
109113
int myBlue = settings.value("/qgis/default_selection_color_blue",0).toInt();
110-
pbnSelectionColour->setPaletteBackgroundColor(QColor(myRed,myGreen,myBlue));
111-
//set teh default color for canvas background
114+
// old Qt3 idiom
115+
// 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+
121+
//set the default color for canvas background
112122
myRed = settings.value("/qgis/default_canvas_color_red",255).toInt();
113123
myGreen = settings.value("/qgis/default_canvas_color_green",255).toInt();
114124
myBlue = settings.value("/qgis/default_canvas_color_blue",255).toInt();
115-
pbnCanvasColor->setPaletteBackgroundColor(QColor(myRed,myGreen,myBlue));
125+
// old Qt3 idiom
126+
// 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);
116131

117132
capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());
118133
}
@@ -122,19 +137,35 @@ QgsOptions::~QgsOptions(){}
122137

123138
void QgsOptions::on_pbnSelectionColour_clicked()
124139
{
125-
QColor color = QColorDialog::getColor(pbnSelectionColour->paletteBackgroundColor(),this);
140+
// old Qt3 idiom
141+
// QColor color = QColorDialog::getColor(pbnSelectionColour->paletteBackgroundColor(),this);
142+
// new Qt4 idiom
143+
QPalette palSelectionColour = pbnSelectionColour->palette();
144+
QColor color = QColorDialog::getColor( palSelectionColour.color(QPalette::Window), this );
126145
if (color.isValid())
127146
{
128-
pbnSelectionColour->setPaletteBackgroundColor(color);
147+
// old Qt3 idiom
148+
// pbnSelectionColour->setPaletteBackgroundColor(color);
149+
// new Qt4 idiom
150+
palSelectionColour.setColor( QPalette::Window, color );
151+
pbnSelectionColour->setPalette(palSelectionColour);
129152
}
130153
}
131154

132155
void QgsOptions::on_pbnCanvasColor_clicked()
133156
{
134-
QColor color = QColorDialog::getColor(pbnCanvasColor->paletteBackgroundColor(),this);
157+
// old Qt3 idiom
158+
// QColor color = QColorDialog::getColor(pbnCanvasColor->paletteBackgroundColor(),this);
159+
// new Qt4 idiom
160+
QPalette palCanvasColor = pbnCanvasColor->palette();
161+
QColor color = QColorDialog::getColor( palCanvasColor.color(QPalette::Window), this );
135162
if (color.isValid())
136163
{
137-
pbnCanvasColor->setPaletteBackgroundColor(color);
164+
// old Qt3 idiom
165+
// pbnCanvasColor->setPaletteBackgroundColor(color);
166+
// new Qt4 idiom
167+
palCanvasColor.setColor( QPalette::Window, color );
168+
pbnCanvasColor->setPalette(palCanvasColor);
138169
}
139170
}
140171
void QgsOptions::themeChanged(const QString &newThemeName)
@@ -187,17 +218,25 @@ void QgsOptions::saveOptions()
187218
settings.writeEntry("/Projections/defaultProjectionSRSID",(int)mGlobalSRSID);
188219

189220
settings.writeEntry("/qgis/measure/ellipsoid", getEllipsoidAcronym(cmbEllipsoid->currentText()));
221+
190222
//set the colour for selections
191-
QColor myColor = pbnSelectionColour->paletteBackgroundColor();
223+
// old Qt3 idiom
224+
// QColor myColor = pbnSelectionColour->paletteBackgroundColor();
225+
// new Qt4 idiom
226+
QColor myColor = pbnSelectionColour->palette().color(QPalette::Window);
192227
int myRed = settings.writeEntry("/qgis/default_selection_color_red",myColor.red());
193228
int myGreen = settings.writeEntry("/qgis/default_selection_color_green",myColor.green());
194229
int myBlue = settings.writeEntry("/qgis/default_selection_color_blue",myColor.blue());
195-
//set teh default color for canvas background
196-
myColor = pbnCanvasColor->paletteBackgroundColor();
230+
231+
//set the default color for canvas background
232+
// old Qt3 idiom
233+
// myColor = pbnCanvasColor->paletteBackgroundColor();
234+
// new Qt4 idiom
235+
myColor = pbnCanvasColor->palette().color(QPalette::Window);
197236
myRed = settings.writeEntry("/qgis/default_canvas_color_red",myColor.red());
198237
myGreen = settings.writeEntry("/qgis/default_canvas_color_green",myColor.green());
199238
myBlue = settings.writeEntry("/qgis/default_canvas_color_blue",myColor.blue());
200-
239+
201240
//all done
202241
accept();
203242
}

src/gui/qgsprojectproperties.cpp

+62-12
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,37 @@
106106
int myGreenInt = QgsProject::instance()->readNumEntry("Digitizing","/LineColorGreenPart",0);
107107
int myBlueInt = QgsProject::instance()->readNumEntry("Digitizing","/LineColorBluePart",0);
108108
QColor myColour = QColor(myRedInt,myGreenInt,myBlueInt);
109-
pbnDigitisedLineColour->setPaletteBackgroundColor (myColour);
109+
// old Qt3 idiom
110+
// pbnDigitisedLineColour->setPaletteBackgroundColor (myColour);
111+
// new Qt4 idiom
112+
QPalette palDigitisedLineColour = pbnDigitisedLineColour->palette();
113+
palDigitisedLineColour.setColor( QPalette::Window, myColour );
114+
pbnDigitisedLineColour->setPalette(palDigitisedLineColour);
115+
110116

111117
//get the colour selections and set the button colour accordingly
112118
myRedInt = QgsProject::instance()->readNumEntry("Gui","/SelectionColorRedPart",255);
113119
myGreenInt = QgsProject::instance()->readNumEntry("Gui","/SelectionColorGreenPart",255);
114120
myBlueInt = QgsProject::instance()->readNumEntry("Gui","/SelectionColorBluePart",0);
115121
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
116-
pbnSelectionColour->setPaletteBackgroundColor (myColour);
122+
// old Qt3 idiom
123+
// pbnSelectionColour->setPaletteBackgroundColor (myColour);
124+
// new Qt4 idiom
125+
QPalette palSelectionColour = pbnSelectionColour->palette();
126+
palSelectionColour.setColor( QPalette::Window, myColour );
127+
pbnSelectionColour->setPalette(palSelectionColour);
128+
117129
//get the colour for map canvas background and set button colour accordingly (default white)
118130
myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
119131
myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
120132
myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
121133
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
122-
pbnCanvasColor->setPaletteBackgroundColor (myColour);
134+
// old Qt3 idiom
135+
// pbnCanvasColor->setPaletteBackgroundColor (myColour);
136+
// new Qt4 idiom
137+
QPalette palCanvasColor = pbnCanvasColor->palette();
138+
palCanvasColor.setColor( QPalette::Window, myColour );
139+
pbnCanvasColor->setPalette(palCanvasColor);
123140
}
124141

125142
QgsProjectProperties::~QgsProjectProperties()
@@ -264,20 +281,29 @@ void QgsProjectProperties::apply()
264281
QgsProject::instance()->writeEntry("Digitizing","/LineWidth",spinDigitisedLineWidth->value());
265282

266283
//set the colour of digitising lines
267-
QColor myColour = pbnDigitisedLineColour->paletteBackgroundColor();
284+
// old Qt3 idiom
285+
// QColor myColour = pbnDigitisedLineColour->paletteBackgroundColor();
286+
// new Qt4 idiom
287+
QColor myColour = pbnDigitisedLineColour->palette().color(QPalette::Window);
268288
QgsProject::instance()->writeEntry("Digitizing","/LineColorRedPart",myColour.red());
269289
QgsProject::instance()->writeEntry("Digitizing","/LineColorGreenPart",myColour.green());
270290
QgsProject::instance()->writeEntry("Digitizing","/LineColorBluePart",myColour.blue());
271291

272292
//set the colour for selections
273-
myColour = pbnSelectionColour->paletteBackgroundColor();
293+
// old Qt3 idiom
294+
// myColour = pbnSelectionColour->paletteBackgroundColor();
295+
// new Qt4 idiom
296+
myColour = pbnSelectionColour->palette().color(QPalette::Window);
274297
QgsProject::instance()->writeEntry("Gui","/SelectionColorRedPart",myColour.red());
275298
QgsProject::instance()->writeEntry("Gui","/SelectionColorGreenPart",myColour.green());
276299
QgsProject::instance()->writeEntry("Gui","/SelectionColorBluePart",myColour.blue());
277300
QgsRenderer::mSelectionColor=myColour;
278301

279302
//set the colour for canvas
280-
myColour = pbnCanvasColor->paletteBackgroundColor();
303+
// old Qt3 idiom
304+
// myColour = pbnCanvasColor->paletteBackgroundColor();
305+
// new Qt4 idiom
306+
myColour = pbnCanvasColor->palette().color(QPalette::Window);
281307
QgsProject::instance()->writeEntry("Gui","/CanvasColorRedPart",myColour.red());
282308
QgsProject::instance()->writeEntry("Gui","/CanvasColorGreenPart",myColour.green());
283309
QgsProject::instance()->writeEntry("Gui","/CanvasColorBluePart",myColour.blue());
@@ -304,28 +330,52 @@ void QgsProjectProperties::showProjectionsTab()
304330

305331
void QgsProjectProperties::on_pbnDigitisedLineColour_clicked()
306332
{
307-
QColor color = QColorDialog::getColor(pbnDigitisedLineColour->paletteBackgroundColor(),this);
333+
// old Qt3 idiom
334+
// QColor color = QColorDialog::getColor(pbnDigitisedLineColour->paletteBackgroundColor(),this);
335+
// new Qt4 idiom
336+
QPalette palDigitisedLineColour = pbnDigitisedLineColour->palette();
337+
QColor color = QColorDialog::getColor( palDigitisedLineColour.color(QPalette::Window), this );
308338
if (color.isValid())
309339
{
310-
pbnDigitisedLineColour->setPaletteBackgroundColor(color);
340+
// old Qt3 idiom
341+
// pbnDigitisedLineColour->setPaletteBackgroundColor(color);
342+
// new Qt4 idiom
343+
palDigitisedLineColour.setColor( QPalette::Window, color );
344+
pbnDigitisedLineColour->setPalette(palDigitisedLineColour);
311345
}
312346
}
313347

314348
void QgsProjectProperties::on_pbnSelectionColour_clicked()
315349
{
316-
QColor color = QColorDialog::getColor(pbnSelectionColour->paletteBackgroundColor(),this);
350+
// old Qt3 idiom
351+
// QColor color = QColorDialog::getColor(pbnSelectionColour->paletteBackgroundColor(),this);
352+
// new Qt4 idiom
353+
QPalette palSelectionColour = pbnSelectionColour->palette();
354+
QColor color = QColorDialog::getColor( palSelectionColour.color(QPalette::Window), this );
317355
if (color.isValid())
318356
{
319-
pbnSelectionColour->setPaletteBackgroundColor(color);
357+
// old Qt3 idiom
358+
// pbnSelectionColour->setPaletteBackgroundColor(color);
359+
// new Qt4 idiom
360+
palSelectionColour.setColor( QPalette::Window, color );
361+
pbnSelectionColour->setPalette(palSelectionColour);
320362
}
321363
}
322364

323365
void QgsProjectProperties::on_pbnCanvasColor_clicked()
324366
{
325-
QColor color = QColorDialog::getColor(pbnCanvasColor->paletteBackgroundColor(),this);
367+
// old Qt3 idiom
368+
// QColor color = QColorDialog::getColor(pbnCanvasColor->paletteBackgroundColor(),this);
369+
// new Qt4 idiom
370+
QPalette palCanvasColor = pbnCanvasColor->palette();
371+
QColor color = QColorDialog::getColor( palCanvasColor.color(QPalette::Window), this );
326372
if (color.isValid())
327373
{
328-
pbnCanvasColor->setPaletteBackgroundColor(color);
374+
// old Qt3 idiom
375+
// pbnCanvasColor->setPaletteBackgroundColor(color);
376+
// new Qt4 idiom
377+
palCanvasColor.setColor( QPalette::Window, color );
378+
pbnCanvasColor->setPalette(palCanvasColor);
329379
}
330380
}
331381
void QgsProjectProperties::on_pbnHelp_clicked()

0 commit comments

Comments
 (0)