[Qgis-developer] Change selection color

Martin Dobias wonder.sk at gmail.com
Wed Feb 5 00:15:31 PST 2014


Hi

On Wed, Feb 5, 2014 at 2:56 PM, hubbatov <hubbatov at mail.ru> wrote:
> Hi! I can`t change selection color using Qt in my app. Can anybody help with
> it?
> QgsMapCanvas::mapRenderer()->rendererContext()->setSelectionColor(QColor)
> not works :(

The renderer context you are accessing is the one that was used
previously for map rendering - for next redraw it will be overwritten.
In general you should not change anything in that context (it would be
better if the context would not be exposed).

The selection color is stored in QgsProject settings, the following
snippet shows how the selection color is read:

  QgsProject* prj = QgsProject::instance();
  int myRed = prj->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
  int myGreen = prj->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
  int myBlue = prj->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
  int myAlpha = prj->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );

... a similar code with "writeEntry" methods will change the selection color.


Regards
Martin


More information about the Qgis-developer mailing list