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

  • SEARCH
  • Home
  • 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 7025873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:02:28+00:00 2026-05-28T00:02:28+00:00

In my PyQt4 program, I retrieve a QColor from the User via QColorDialog. I

  • 0

In my PyQt4 program, I retrieve a QColor from the User via QColorDialog.
I then need to format this QColor to be used in a Style Sheet, which I currently achieve by calling…

QColor.name()

… which returns something like ‘#00ff00’ which would then undergo simple string manipulation to be set as a style sheet for a widget. eg:

QWidget.setStyleSheet( '* { background-color: '+ QColor.name() + ' }')

Later in the program, the background color of the widget must be fetched (using .styleSheet() and more simple string manipulation) and converted to a string which when eval()ed, would construct a QColor of the identical color.

It must be converted to a QColor, since it is later used in a QBrush. The QColor must be converted to a one line string because it is written to file, and imported from said file via eval().
(The string when eval()ed must pass the color to the QColor constructor, since the string is only one line).

In the end, I need something similiar (though not possible in this manner) like this:

ColorString = str( QtGui.QColorDialog.getColor().name() )
EvalString = "QtGui.QColor(" + ColorString +")"

Ofcourse, this method doesn’t work because the QColor constructor does not accept such a format as ‘#00ff00’ which is the format that QColorDialog.name() gives and which a QWidget.setStyleSheet() accepts.

How can I actually achieve this?

Is there anyway to convert a string like ‘#00ff00’ to 3 integers representing Red, Green and Blue which could then be sent to the QColor constructor?
Thanks!

Note:
I realise that such a format ‘#00ff00’ does involve a representation of those three colours, but I don’t understand what ‘ff’ means, and calling .red() on a QColor does not return the integer that is suggested by the ‘#00ff00’ format.
It’s probably obvious that I don’t understand colors 🙂

Specs:
– PyQt4
– Python 2.7
– Windows 7

  • 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-28T00:02:29+00:00Added an answer on May 28, 2026 at 12:02 am

    Try QColor.setNamedColor(name)

    Example:

    string_with_color = '#00ff00'  # gathered somehow
    
    color = QtGui.QColor(0, 0, 0)
    color.setNamedColor(string_with_color)
    

    but I don’t understand what ‘ff’ means

    ff = 255 in hexadecimal system

    EDIT

    As appears from the comments, solution was to convert Python string to QString

    EvalString = "QtGui.QColor(QtCore.QString(" + ColorString +"))"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program using python 2.6 and pyqt4. I want this program to
Ive created a program using pyqt4 as GUI Ive used resource file or .qrc
I can't figure out why this program is failing. #!/usr/bin/env python from __future__ import
I want to capture output from a C program I'm launching like this: p
I'm developing a PyQt program that will soon switch from an xml type backend
The PyQt4 QTableWidget has both cellPressed and cellClicked signals. From the name, and the
I'm creating a User Interface using PyQt4 module . the problem i'am facing is
I'm trying to dynamically create buttons at runtime with PyQT4.7 However, this being my
I am working on python plugins.I designed my form using pyqt4 designer. I used
I have a Python program uses Qt (PyQt4 in fact) and when I launch

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.