Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6967795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:22:06+00:00 2026-05-27T16:22:06+00:00

I wish to have a large array of QColors that many classes will share

  • 0

I wish to have a large array of QColors that many classes will share and index from.

In the past, I’ve always had the list like such:

QColor colours[10] = {QColor("cyan"), QColor("magenta"), QColor("red"),
                      QColor("darkRed"), QColor("darkCyan"), QColor("darkMagenta"),
                      QColor("green"), QColor("darkGreen"), QColor("yellow"),
                      QColor("blue")};

However, now I want many more than 10. How can I create a large list of different QColors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:22:07+00:00Added an answer on May 27, 2026 at 4:22 pm

    if you want your list to be dynamic, I would use some sort of QVector instead, wrapped in a Color Manager for example :

    
        class ColorManager
        {
            public:
                ColorManager(size_t iDefaultSize)
                {
                    m_colorList.reserve(iDefaultSize);
                }
    
                void addColor(const QColor& c)
                {
                    m_colorList.push_back(c);
                }
    
                QColor& operator[](int iIndex)
                {
                    return m_colorList.at(iIndex);
                }
    
            private:
                QVector m_colorList;
        };
    
    

    If your colors have to be unique, consider using a QSet, but you loose the [] operator as QSet are ordered structure, and you will have to implement a find in ColorManager, using QSet::find(). It will also be slower.
    If it has to be thread safe, you can eventually protect it with QMutex.

    Also, I don’t know why you need this, but you should have a look at :

    QColorGroup and / or QPalette

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large function that I wish to load only when it is
I have a large dataset (over 100,000 records) that I wish to load into
I have a large system that I have coded and I wish to make
I have a large database of XHTML that I wish to render as PDFs
I have a large-ish file (4-5 GB compressed) of small messages that I wish
I have a large amount of data that is retrieved from a database. They
I have a rather large (many gigabytes) table of data in SQL Server that
I have a large 1D dynamic array in my program that represents a FITS
I have several large websites that I wish to create a WIX installer for.
I have a large collection of documents scanned into PDF format, and I wish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.