Accessing RGB values of RColor object

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
ScottP
Junior Member
Posts: 14
Joined: Wed Jul 08, 2020 5:08 pm

Accessing RGB values of RColor object

Post by ScottP » Fri Jul 31, 2020 10:13 pm

Hello,

How can I access each R,G,B value spanning 0 to 255 from an RColor object returned by getColor(REntity)? The API shows that RColor objects can contain R,G,B,A integers, or QString objects, or QColor objects. How can I force interpretation of the object as R,G,B,A integers?

My task is to find & store the RGB values of all uniquely colored entities from a document, like this:

Code: Select all

aColor = [0,0,0,255];//RGBA black is always present
uniqueColors = [aColor];//javascript does not directly support multidimensional arrays
allEntityIds = document.queryAllEntities();
for(var e = 0; e < allEntityIds.length; e++){
	var entity = queryEntity(allEntityIds[e]);
	var color = entity.getColor(); //hoping to get colors as a 4-element array for R,G,B,A
	var uniqueColor = true;
	for(var c = 0; c < e; c++){
		if(color == uniqueColors[c]){ // uniqueColors is a 4-element array for R,G,B,A
			uniqueColor = false;
		}
	}
	if(uniqueColor){
		uniqueColors.push([color[0], color[1], color[2], color[3]]);// need to access RGBA values
	}
}
Last edited by ScottP on Tue Aug 04, 2020 5:25 pm, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Accessing RGB values of RColor object

Post by andrew » Sat Aug 01, 2020 10:20 am

You can use:

Code: Select all

color.red()
color.green()
color.blue()
color.alpha()
See also:
RColor API (derrived from QColor)
QColor API

ScottP
Junior Member
Posts: 14
Joined: Wed Jul 08, 2020 5:08 pm

Re: Accessing RGB values of RColor object

Post by ScottP » Wed Aug 05, 2020 12:43 am

Easy, thanks!

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”