Results 1 to 10 of 10

Thread: How to get color pixel in QML?

  1. #1
    Join Date
    Oct 2013
    Location
    VietNam
    Posts
    41
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Question How to get color pixel in QML?

    Hi!
    I want get color pixel when i click in QML. But i don’t know that the work fucntion.
    Please help me!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get color pixel in QML?

    Quote Originally Posted by tanthinh1510 View Post
    Hi!
    I want get color pixel when i click in QML. But i don’t know that the work fucntion.
    In general case this is not possible. Why do you need that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    tanthinh1510 (25th October 2014)

  4. #3
    Join Date
    Oct 2013
    Location
    VietNam
    Posts
    41
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: How to get color pixel in QML?

    Hi wysota! thanks for your reply.
    I have Rectangle with color animation, and then a put small circle in Rectangle. I want get color of pixel center circle when color animation changed.
    I show you in the picture!
    Untitled.png

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get color pixel in QML?

    Do you mean you want to fill the circle with the color corresponding to the color of the gradient underneath? Then either:
    1. calculate the color manually (shouldn't be that hard)
    2. implement a ShaderEffect to probe the texture of the gradient element and fill the circle with that color
    3. put a ShaderEffectSource of the gradient element in the circle and stretch it so much that a single texel spans across the whole circle diameter (which might be hardest of the three approaches).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Oct 2013
    Location
    VietNam
    Posts
    41
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: How to get color pixel in QML?

    Hi wysota!
    Can you for me simple example "implement a ShaderEffect to probe the texture of the gradient element and fill the circle with that color"?
    Because I don't know how to get color of pixel in gradient color animation by ShaderEffect!
    thanks wysota!


    Added after 7 minutes:


    Hi wysota!
    I wan to create the software similar this video, have any idea wysota?

    Last edited by tanthinh1510; 26th October 2014 at 07:22.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get color pixel in QML?

    Quote Originally Posted by tanthinh1510 View Post
    Can you for me simple example "implement a ShaderEffect to probe the texture of the gradient element and fill the circle with that color"?
    There is no "simple example" for that. And if you don't know GLSL, you wouldn't understand it anyway. Better stick with calculating the color manually, it shouldn't be that hard as you are dealing with a linear gradient.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Oct 2013
    Location
    VietNam
    Posts
    41
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: How to get color pixel in QML?

    Please tell me, what I need to learn to do as the video above by QT?
    Thanks wysota so much!

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get color pixel in QML?

    Quote Originally Posted by tanthinh1510 View Post
    Please tell me, what I need to learn to do as the video above by QT?
    You need to calculate the color of the linear gradient under cursor using a simple linear equation. The difference between start and stop point of the gradient divided by the width of the gradient gives you the "speed" of colour change over one unit of width (e.g. one pixel). Knowing that you can interpolate the colour over the whole gradient.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #9
    Join Date
    Oct 2013
    Location
    VietNam
    Posts
    41
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: How to get color pixel in QML?

    Hi wysota!
    I just get color of pixel center circle when color animation changed.
    Circle below shows the color of the cursor.
    results shows in this video!

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get color pixel in QML?

    Congratulations. You can post your solution here in case someone else encounters a similar problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to get color of pixel or point?
    By qt_developer in forum Newbie
    Replies: 2
    Last Post: 28th June 2012, 20:14
  2. How to read a color of a pixel on a Widget?
    By wringer in forum Newbie
    Replies: 5
    Last Post: 4th December 2009, 07:31
  3. How to get pixel color from QPainter ??
    By rameshg87 in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2008, 09:58
  4. getting color from a pixel on canvas
    By teeshift in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 05:12
  5. How to get color of pixel or point by QMouseEvent
    By Krishnacins in forum Newbie
    Replies: 4
    Last Post: 28th May 2006, 02:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.