Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QGradient::color(pos);?



  • I want to use a Q(Linear)Gradient in a way that is similar to a colour chooser. But given a position there doesn't appear to be a way to extract the colour at that position which seems rather a shame.

    Is there any easy way to achieve this? If necessary I can try to locate the source repository and "borrow" the relevant code... Are there any protected methods I could use to achieve this that aren't in the documentation?

    This is a bit more complex than just finding the colour at one of the defined stops which is trivial. The control I'm working on would also allow you to double click between stops to add an extra stop, hence the wish to find the colour at a specific position.

    David


  • Qt Champions 2019



  • I was thinking in terms of the QGradient position value (i.e. 0.0 to 1.0) rather than using some form of pixel under mouse technique as the rodent won't necessarily be in the gradient but may well be next to it where the markers are held (not 100% trivial to convert to a position where it would be over the gradient itself):

    0c70aa8a-1d7e-4e33-a101-dca4948df042-image.png

    Thanks
    David


Log in to reply