Results 1 to 12 of 12

Thread: Need advice on getting HSI color from an Image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  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

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

  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

    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.

  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

    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()

  5. #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

    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..

  6. #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

    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.

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

    ramstormrage (4th May 2008)

  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

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

  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

    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
  •  
Qt is a trademark of The Qt Company.