Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QImage::pixel() in QML

QImage::pixel() in QML

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 7.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    guillaume.belz
    wrote on last edited by
    #1

    For Qt exercise, I try tro write ColorPicker in QML. I have no problem to create gradients and mouse management : "image on forum":http://www.developpez.net/forums/d965869/c-cpp/bibliotheques/qt/contribuez/exercice-qt-color-picker-premiere-partie/#post5422837

    I want to send signal on click with selected color. But I can't know color of pixel at given position.

    Have you ideas to do this ?

    PS : I have 2 solutions to do this : create specific QObject to store image and pick color and calcul RGBA parameters with x,y position. But I want to know if they are more simple solution

    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      AFAIK there is no other solution than calculate color from x,y pair

      1 Reply Last reply
      0
      • G Offline
        G Offline
        guillaume.belz
        wrote on last edited by
        #3

        Thanks for reply

        I do with x,y values

        After the end of exercise, I send link with code here, those who would be interested.

        Thanks

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          yes, you could also add a howto wiki page for this

          1 Reply Last reply
          0
          • G Offline
            G Offline
            guillaume.belz
            wrote on last edited by
            #5

            The code I had write :

            @import Qt 4.7

            Item
            {
            width: 256
            height: 256

            function updateSelectedColor()
            {
                ColorPickerContext.selected_red =
                        (1 - (cursor.y / height)) *
                        (1 + (cursor.x / width) * (main_red - 1))
                ColorPickerContext.selected_green =
                        (1 - (cursor.y / height)) *
                        (1 + (cursor.x / width) * (main_green - 1))
                ColorPickerContext.selected_blue =
                        (1 - (cursor.y / height)) *
                        (1 + (cursor.x / width) * (main_blue - 1))
            }
            
            Rectangle
            {
                width: parent.height
                height: parent.width
                transform: Rotation { angle: 90}
                x: parent.width
                y: 0
                gradient: Gradient
                {
                    GradientStop { position: 0.0; color: 
                                   Qt.rgba(main_red, main_green, main_blue, 1)}
                    GradientStop { position: 1.0; color: "white" }
                }
            }
            
            Rectangle
            {
                anchors.fill: parent
                gradient: Gradient
                {
                    GradientStop { position: 0.0; color: Qt.rgba(0, 0, 0, 0) }
                    GradientStop { position: 1.0; color: Qt.rgba(0, 0, 0, 1) }
                }
            }
            
            Image
            {
                id: cursor
                x: width/2
                y: height/2
                source: "cursor.png"
            }
            
            MouseArea
            {
                acceptedButtons: Qt.LeftButton
                anchors.fill: parent
                onPressed:
                {
                    cursor.x = mouseX - 4
                    cursor.y = mouseY - 4
                    updateSelectedColor()
                }
                onPositionChanged:
                {
                    cursor.x = mouseX - 4
                    cursor.y = mouseY - 4
                    updateSelectedColor()
                }
            }
            

            }@

            I'm not expert in QML, so if someone have critics, I'm interessed.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved