Results 1 to 12 of 12

Thread: Need advice on getting HSI color from an Image

  1. #1
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Need advice on getting HSI color from an Image

    Hello experts.

    I have an image viewer which has a dialog that has a frame whose color can be modified by the Color Dialog. However, I would also like to change the frame's color depending on the color chosen from the image on the Main Window (like the dropper tool from Windows Paint program).
    Could someone kindly give me a general solution for this task?

    I would like to know also where should I reimplement the mousePressEvent - in the mainwindow or the dialog?

    Thank you very much for your help. It would be greatly appreciated.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need advice on getting HSI color from an Image

    Subclass the widget on which you paint the image(label, generic widget, etc) and override the mousePressEvent or the mouseReleaseEvent function.

    Also you should still keep a reference to the pixmap that was set as background. When you get a mouse click just look in the pixamp at the click coordinates and get the RGB value.
    You'lll have to convert that to HSI.

  3. #3
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need advice on getting HSI color from an Image

    Quote Originally Posted by marcel View Post
    .. coordinates and get the RGB value.
    You'lll have to convert that to HSI.
    This, I have taken care of already.

    Quote Originally Posted by marcel View Post
    Subclass the widget on which you paint the image(label, generic widget, etc) and override the mousePressEvent or the mouseReleaseEvent function.
    But this, I do not quite get. Do you mean I should reimplement the QLabel that holds the Pixmap and change the mouse events? Sorry im not quite familiar at mouse events.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need advice on getting HSI color from an Image

    Not reimplement entirely. Just subclass and override QWidget::mousePressEvent. Here you should use the pixmap() property of QLabel to get the QRgb at the position where the mouse was clicked inside the label.

    Since you mentioned now that it is a QLabel, then you will need and additional signal to notice the outside world when the color should change, and to which color. The signal should take a Qrgb parameter and you should connect it to the object that takes care of changing the color of the frame.

    Hope it's clear now.

  5. The following user says thank you to marcel for this useful post:

    ramstormrage (4th May 2008)

  6. #5
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need advice on getting HSI color from an Image

    Thank you. Ill post again when I get stuck or confused again.

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need advice on getting HSI color from an Image

    You're welcome...
    Just one thing: the signal I mentioned earlier should be emitted from the label's mousePressEvent.

  8. #7
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need advice on getting HSI color from an Image

    Hello again.

    I subclassed QLabel and got to the point where I assign the position of the mouse event to a QPoint. Now, I understand that I need to use this QPoint to get the QRgb value of whatever is underneath. Question, how do I do this?

    Here you should use the pixmap() property of QLabel to get the QRgb at the position where the mouse was clicked inside the label.

  9. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need advice on getting HSI color from an Image

    Oh, yes... Forgot all about that. QPixmap doesn't expose pixel data. You could convert it to a QImage, although this adds a bit of extra overhead:

    Qt Code:
    1. QImage img = pixmap()->toImage();
    2.  
    3. .... later, in mousePressEvent
    4. QRgb color = img.pixel(mouseX, mouseY);
    To copy to clipboard, switch view to plain text mode 
    You could create a member QImage so you don't have to convert the pixmap at every mouse click.

    See QImage::pixel
    QPixmap::toImage and QLabel::pixmap()

  10. #9
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need advice on getting HSI color from an Image

    Ok Ill give it a go thanks.

    Marcel, Id like to put in a few more questions if you dont mind. If my custom frame is on a dialog, whats the easiest way to return to Main Window to pick a color then return again to the dialog to display the color? I understand that the dialog should be modeless..

  11. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need advice on getting HSI color from an Image

    Yes, the dialog should be modeless, otherwise you couldn't interact with the main window. You could set the flags of the dialog to be Qt::Tool. This is usually done for palette windows, like in Photshop and Visual Studio.

    Once you select a color in the main window you could transmit it to the dialog via a signal. The signal should be emitted by the main window itself or by an object the main window contains.

    In order to add a custom slot to the dialog you will have to subclass it.

  12. The following user says thank you to marcel for this useful post:

    ramstormrage (4th May 2008)

  13. #11
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need advice on getting HSI color from an Image

    Alright! Im learning new stuff..
    Ok thanks again, youve been a great help.

  14. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need advice on getting HSI color from an Image

    no problem

Similar Threads

  1. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  2. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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.