[Solved] App::PropertyColor erroneous behavior

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

[Solved] App::PropertyColor erroneous behavior

Post by Evgeniy »

In short. Create some part... For example, the Cube in the workbench Part.
Open the View tab and try set the 'Shape Color' property, for example.

As a color, specify for example: red = 50, green = 100, blue = 200.

Press 'Ok', and then check which values are written to the property.

And you will see: red = 51, green = 99, blue = 198.

PropertyColor.gif
PropertyColor.gif (206.4 KiB) Viewed 1324 times

It was checked in Windows, perhaps this error is missing in other operating systems.

Code: Select all

OS: Windows 10
Word size of FreeCAD: 64-bit
Version: 0.21.0.31432 (Git)
Python 3.10.8, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3

I think this is due to the fact that the property App::PropertyColor uses a float color model like: (1.0, 1.0, 1.0, 1.0) and the color dialog returns values in the integer format like (255, 255, 255, 255) and after several conversions from integer to float and back, the color accuracy is lost.
Last edited by Evgeniy on Fri Feb 17, 2023 8:52 am, edited 1 time in total.
user1234
Veteran
Posts: 3345
Joined: Mon Jul 11, 2016 5:08 pm

Re: [Bug] App::PropertyColor erroneous behavior

Post by user1234 »

Evgeniy wrote: Sun Jan 15, 2023 10:17 pm It was checked in Windows, perhaps this error is missing in other operating systems.
I also noticed that recently, the question is if that is a QT issue.

Code: Select all

OS: Debian GNU/Linux 11 (bullseye) (X-Cinnamon/lightdm-xsession)
Word size of FreeCAD: 64-bit
Version: 0.21.0.31599 (Git)
Build type: Release
Branch: master
Hash: 12ed13ddbea126b40546d5b3d67fdeb6abeeece9
Python 3.9.2, Qt 5.15.2, Coin 4.0.0, Vtk 9.0.1, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * QuickMeasure 2022.10.28
  * CurvedShapes 1.0.4
  * Curves 0.6.5

Greetings
user1234
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Bug] App::PropertyColor erroneous behavior

Post by Evgeniy »

user1234 wrote: Sun Jan 15, 2023 10:26 pm I also noticed that recently, the question is if that is a QT issue.

Code: Select all

from PySide2.QtGui import QColor
# Create color from integers
c = QColor(50,100,200,255)
# Convert integers to floats
cf = c.getRgbF()
# Create color from floats
nc = QColor()
nc.setRgbF(cf[0],cf[1],cf[2],cf[3])
# Convert floats to integers
print(nc.getRgb())
Doesn't look like... After several transformations, the result is the same... (50, 100, 200, 255)

It seems to me, in core is some code that uses its unreliable formulas instead of Qt methods for calculations.
user1234
Veteran
Posts: 3345
Joined: Mon Jul 11, 2016 5:08 pm

Re: [Bug] App::PropertyColor erroneous behavior

Post by user1234 »

There was no QT update for a while. But as i remember, a few years ago, there was a similar issue.

Greetings
user1234
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Bug] App::PropertyColor erroneous behavior

Post by Evgeniy »

User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [Bug] App::PropertyColor erroneous behavior

Post by Roy_043 »

The Decimals preference (Preferences_Editor#Units) is wrongly used to round the color values. Just play with that value and check the Python console after applying a color.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Bug] App::PropertyColor erroneous behavior

Post by openBrain »

Merged a fix today.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Solved] App::PropertyColor erroneous behavior

Post by Evgeniy »

Thanks. All work fine.
Post Reply