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 7098145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:01:07+00:00 2026-05-28T11:01:07+00:00

In my application, a User clicks on any widget of my program (which are

  • 0

In my application, a User clicks on any widget of my program (which are at the time; dormant) and picks a color for it.
This color will then be added to a stylesheet for that particular widget.

However, when the program ends and is started again, I would like that particular widget to retain its stylesheet.
I would like to not have to hard code in stylesheets for every widget. In fact, I’d rather not even know which particular widget is having the stylesheet.

What I’d really like to do is have a single style sheet for the application, and code the new color just to the particular widget clicked.

(ie: If the User clicked on a QPushButton and chose a stylesheet of { color: red},
I would like just THAT QPushButton red and none others.
So, if that QPushButton had a variable name of ‘Clicky’,
to the QApplications stylesheet I would add:
‘QPushButton#Clicky { color: red }’ )

To do this and not have to hard-code it in for every widget,
I must somehow convert the variable name of my PyQt4 widgets to strings.
How can I do this?

Thanks!

(I’ve read it can be extremely difficult to get python variable names from their values;
Is there any other form of ID for a widget that can be added to a stylesheet?)


PyQt4
python 2.7.2
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-28T11:01:08+00:00Added an answer on May 28, 2026 at 11:01 am

    You need to first setObjectName(“somename”) before an object is named, then objectName() will work, or even better – findChild(), or findChildren()

    Example

    header:

    QButton foo;
    

    class:

    foo = new QButton();
    foo.setObjectName("MySuperButton");
    

    Then, finally in your QSS..

    #MySuperButton { 
         background: black;
    }
    

    This also works similarly to CSS with

    QButton#MySuperButton {
         background: red;
    }
    

    The logic behind why you’d want to set multiple object names similarly (for different objects), or use the granularity of only one type of widget with a specific name is also pretty much the same as CSS.

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

Sidebar

Related Questions

In my application when a user clicks on a button I want to open
In my ASP.Net application I have a requirement that when a user clicks on
In a fictitious web application ... The user clicks a link The server starts
I have created an application that runs in the taskbar. When a user clicks
Context: There's an application where you draw things on canvas. Where user clicks there's
I have an ASP.NET MVC application, when a user clicks on the submit button
I have 4 tabs in my iphone application. When user will click a button
I have integrated Facebook connect in my iphone application. when user clicks on a
I have a widget containing multiple child objects, which the user can select by
I have a simple application where a user clicks on an area, and the

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.