TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #62 · 4 апр.

Когда разрабатываете свой GUI с помощью PyQt для какого-либо софта бывает необходимо позаимствовать цвета из текущего стиля интерфейса. Например, чтобы правильно раскрасить свои виджеты, подогнав их по цвету. Ведь бывает, что ваш GUI используется в разных софтах. Причём некоторые со светлой темой а другие с тёмной. По умолчанию стили наследуются, но если вы задаёте какую-либо раскраску для части виджета через свой styleSheet, то требуется ссылаться на цвета текущего стиля. Как это сделать? Как получить нужный цвет из палитры имеющегося стиля? Это достаточно просто, нужно использовать класс QPalette и его роли. Например, мне нужно достать цвет текста из одного виджета и применить его в другом как цвет фона (не важно зачем именно так, просто захотелось😊). Получаем палитру виджета и сразу достаём нужный цвет, указав его роль. from PySide2.QtGui import QPalette color = main_window.palette().color(QPalette.Text) теперь можем использовать этот цвет в стилях my_widget.setStyleSheet(f'background-color: {color.name()};') Готово, мы динамически переопределили дефолтный стиль используя текущий стиль окна! На самом деле есть запись покороче, в одну строку и без лишних переменных. Не очень-то по правилам CSS, но Qt это понимает. my_widget.setStyleSheet('background-color: palette(Text);') Этот способ не подходит если вам нужно как-то модифицировать цвет перед применением в своих стилях. В этом случае потребуется первый способ. Зато он прекрасно сработает в файле .qss, то есть не придётся в коде прописывать раскраску отдельных элементов через ссылки на палитру, всё красиво сохранится в отдельном файле .qss! QListView#my_widget::item:selected { background: palette(Midlight); } Про имеющиеся роли можно почитать здесь🌍 #qt#tricks

Hashtags

Резултати

Пронајдени 17 слични објави

Пребарај: #legendary

当前筛选 #legendary清除筛选
Everything Science

@everything_science · Post #3857 · 31.12.2025 г., 08:54

Tired of getting viruses? Do this. Clean your motherboard daily to make sure those viruses get wiped off your computer forever. #legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3435 · 05.05.2025 г., 07:49

By writing "sorry" at the bottom of your math test, your teacher will feel sorry for you and probably pass you. #Legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3350 · 23.03.2025 г., 09:37

Virgin Airlines has announced that from July 2017 they will also be accepting passengers who are not virgins any more. #Legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3344 · 19.03.2025 г., 18:14

This poor man passed away yesterday when his family couldn't remember his blood type. As he died, he kept insisting for his children to "be positive" What a caring father. A loving man. #Legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3273 · 10.02.2025 г., 18:25

During child birth, the pain is so intense that women are almost capable of feeling what a man feels when he hears "I love you as a friend" #Legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3264 · 04.02.2025 г., 11:03

"Peeing in the sink is actually the green way to go, so you're welcome. Instead of wasting 1.6 gallons of water on a flush, you pee in the sink. You then wash your hands in that very same sink, simultaneously washing down the urine and preserving nature's most precious resource." #Legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3257 · 02.02.2025 г., 07:41

PEARL HARBOR was an inside job, there's no way Japanese planes could've flown THIS distance in 1931. Wake up retards and realise your government has been lying to you, JAPAN is innocent #Legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3255 · 01.02.2025 г., 07:43

Did you know ? In the 90s Arsenal Soccer Club had a player called David Dicks. When he was injured, the Newspaper wrote"Arsenal to play without Dicks". The coach was upset so the Newspaper changed the headline to read "Arsenal to play with Dicks out"... A record number of women attended the match. #Legendary 🔔@Everything_Science

Hashtags

Everything Science

@everything_science · Post #3248 · 30.01.2025 г., 08:16

name ur daughter lizard then give her the nickname Liz and people will b like oh that's short for Elizabeth? and she'll be like no my name is lizard #Legendary 🔔@Everything_Science

Hashtags

12
ПретходнаСтраница 1 од 2Следна