Results 1 to 6 of 6

Thread: Generating distinguishes colors from QColor::colorNames()

  1. #1
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    18
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question Generating distinguishes colors from QColor::colorNames()

    Hi
    I wrote a small loop in c++ for generating colors from QColor::colorNames(). But it generates it reaaaaly randomly, so together they look really really bad.
    Is there any idea how to generate distinguishable colours(blue, red, green, yellow, orange, white etc.) first? I know it depence from i-value in loop, but no idea how to set it
    Here is my code:

    Qt Code:
    1. QStringList colorName = QColor::colorNames();
    2. QVector<QColor> colorCat(numCat); // number of categories I have to color
    3. for(int i =0; i < numCatt; i++)
    4. colorCat[i] = colorName[i]; //I also tried something like colorName[2*i], or [i*i] to generate something normal, but it failed
    To copy to clipboard, switch view to plain text mode 
    Last edited by time; 9th November 2016 at 23:16.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Generating distinguishes colors from QColor::colorNames()

    I guess the easiest way is to predefine a list of colors according to your criteria an take values from there when needed.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    18
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Generating distinguishes colors from QColor::colorNames()

    Quote Originally Posted by anda_skoa View Post
    I guess the easiest way is to predefine a list of colors according to your criteria an take values from there when needed._
    Hello, thank you for answer.
    The idea is not bad, but unfortunatelly I don't know how many colors I will be need. So it can be 4 or 44, or maybe 100. So predefine 100 colors is not the 'clever' way to solve this problem, but obviously I can do that and it will be working
    But I am looking for some universal way to make colors.
    Cheers!

  4. #4
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Generating distinguishes colors from QColor::colorNames()

    What you also could do (if you can avoid using colorNames()) is to create the colors yourself on-the-fly. Have a look at the standard color wheel, just subdivide the HUE value by the amount of colors you need. Finally sort your color list so that each color has a neighbor with it's very opposite color. This way you could create a list like: [red, cyan, yellow, blue ...] which is pretty much as distinguishable as it can get.

  5. #5
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    18
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Generating distinguishes colors from QColor::colorNames()

    Thank you. But how I can do that without colorNames()? I don't understand the idea on-the-fly

  6. #6
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Generating distinguishes colors from QColor::colorNames()

    On-the-fly just meant when required. QColor provides a method called fromHsv(). You calculate the designated hue and pass it to the function. The result is your color. Just calculate hue values in such way that neighboring colors in your list differ by 180 (degrees).

Similar Threads

  1. QColor generator?
    By Khaine in forum Qt Programming
    Replies: 2
    Last Post: 30th March 2016, 11:35
  2. Doubt In QColor::colorNames()
    By vinodpaul in forum Newbie
    Replies: 1
    Last Post: 24th July 2012, 08:21
  3. question with QColor
    By Devora in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2009, 11:49
  4. bug with QColor(QString& name)
    By Radagast in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2008, 15:24
  5. MFC PALLETEINDEX to QColor()
    By maverick_pol in forum Qt Programming
    Replies: 8
    Last Post: 24th September 2007, 08:10

Tags for this Thread

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.