How to get the background color of a button or label (QPushButton, QLabel) in PyQt

2024/9/30 19:34:23

I am quite new to PyQt. Does anyone tell me how to get the background color of a button or label (QPushButton, QLabel) in PyQt.

Answer

Here is a sample code. This will help you.

QPushButton button1, button2;
button1.setStyleSheet("background-color:#ff0000;");//To get Background color
QColor color = button1.palette().button().color();//To set fetched color
button2.setStyleSheet("background-color:" + color.name() +";");
https://en.xdnf.cn/q/71049.html

Related Q&A

Is it possible to make sql join on several fields using peewee python ORM?

Assuming we have these three models.class Item(BaseModel):title = CharField()class User(BaseModel):name = CharField()class UserAnswer(BaseModel):user = ForeignKeyField(User, user_answers)item = Foreign…

Django multiple form factory

What is the best way to deal with multiple forms? I want to combine several forms into one. For example, I want to combine ImangeFormSet and EntryForm into one form:class ImageForm(forms.Form):image =…

How to include the private key in paramiko after fetching from string?

I am working with paramiko, I have generated my private key and tried it which was fine. Now I am working with Django based application where I have already copied the private key in database.I saved m…

SHA 512 crypt output written with Python code is different from mkpasswd

Running mkpasswd -m sha-512 -S salt1234 password results in the following:$6$salt1234$Zr07alHmuONZlfKILiGKKULQZaBG6Qmf5smHCNH35KnciTapZ7dItwaCv5SKZ1xH9ydG59SCgkdtsTqVWGhk81I have this snippet of Python…

Running python scripts in Anaconda environment through Windows cmd

I have the following goal: I have a python script, which should be running in my custom Anaconda environment. And this process needs to be automatizated. The first thing Ive tried was to create an .exe…

How to work out ComplexWarning: Casting complex values to real discards the imaginary part?

I would like to use a matrix with complex entries to construct a new matrix, but it gives me the warning "ComplexWarning: Casting complex values to real discards the imaginary part".As a resu…

Is it possible to use POD(plain old documentation) with Python?

I was wondering if it is possible to use POD(plain old documentation) with Python? And how should I do it?

ctypes error AttributeError symbol not found, OS X 10.7.5

I have a simple test function on C++:#include <stdio.h> #include <string.h> #include <stdlib.h> #include <locale.h> #include <wchar.h>char fun() {printf( "%i", 1…

Filtering negative timedeltas

Consider a series holding timedelta64[ns] that measures at the time difference between two events A and B:> time_deltas499900 -1 days +23:45:13 499916 -1 days +23:50:57 499917 00:03:2…

What is the Matlab equivalent of the yield keyword in Python?

I need to generate multiple results but one at a time, as opposed to everything at once in an array.How do I do that in Matlab with a generator like syntax as in Python?