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

Резултати

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

Пребарај: #reducereuserecycle

当前筛选 #reducereuserecycle清除筛选
NEA Singapore

@NEASingapore · Post #560 · 05.06.2023 г., 23:45

Getting excited over the 6.6 sales? Ask yourself if you really need the item before adding it to your cart! Consider using or repairing what you have, instead of replacing it. #ReduceReuseRecycle Check out some tips here: https://www.youtube.com/playlist?list=PLPX9rYUbMZF3GLoLkP2Bxd0TelSHylBOu

NEA Singapore

@NEASingapore · Post #55 · 20.05.2020 г., 10:00

It can be very tempting to do online shopping this circuit breaker period, but think about whether you really need it before you put it in your cart! #ReduceReuseRecycle

NEA Singapore

@NEASingapore · Post #450 · 25.10.2022 г., 00:45

Dressing up as your favourite superhero this Halloween? Get creative and make a costume using everyday household items. When you’re done, recycle or reuse what you can of your outfit, so that your superhero legacy will continue to live on 🦸‍♂️ #3Rs#ReduceReuseRecycle

NEA Singapore

@NEASingapore · Post #1080 · 10.07.2025 г., 01:03

60 years of progress, but what’s next for Singapore? Higher temperatures, more wet and dry extremes, and accelerating increase in mean sea levels are projected. In the worst-case scenario, the 𝗺𝗲𝗮𝗻 𝘀𝗲𝗮 𝗹𝗲𝘃𝗲𝗹 around Singapore is projected to 𝗿𝗶𝘀𝗲 𝗯𝘆 𝟭.𝟭𝟱𝗺 𝗯𝘆 𝘁𝗵𝗲 𝗲𝗻𝗱 𝗼𝗳 𝘁𝗵𝗲 𝗰𝗲𝗻𝘁𝘂𝗿𝘆, and up to 𝗮𝗿𝗼𝘂𝗻𝗱 𝟮𝗺 𝗯𝘆 𝟮𝟭𝟱𝟬. Let’s commit to a sustainable future by taking climate actions to reduce our waste and carbon footprint. #3Rs#ReduceReuseRecycle#SG60

NEA Singapore

@NEASingapore · Post #1095 · 09.08.2025 г., 01:02

Happy 60th National Day, Singapore! 🇸🇬 As we celebrate our progress as a nation, let’s also commit to building a #SustainableSG for present and future generations. Let’s reduce our carbon footprint by taking climate actions such as adopting energy-saving and #ReduceReuseRecycle habits. #SG60#KeepSGClean

NEA Singapore

@NEASingapore · Post #645 · 18.09.2023 г., 03:31

#ProTip: There’s no need to sort your recyclables! Paper, plastic, glass, and metal can all be placed in the recycling bins ♻️✌️ But do remember to CHECK and CLEAN before you RECYCLE: www.go.gov.sg/recycleright #RecycleRight#ReduceReuseRecycle

NEA Singapore

@NEASingapore · Post #1012 · 22.03.2025 г., 01:04

Switch off for #EarthHour at 8:30pm! But let's not stop there. Let this yearly reminder inspire us to continue making sustainable choices. Your everyday choices matter more than you might think! Small steps such as adopting energy-saving habits and recycling right can make a difference. Imagine these small acts being amplified by millions worldwide. 🌍💚 #EnergyEfficiency#ReduceReuseRecycle#RecycleRight

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