Когда разрабатываете свой 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
🇬🇧Popular English Idioms to Sound Like a Native Speaker
💣 BLEW ME AWAY:
✍🏽when something blows you away, you’re extremely impressed by it
🔺The exhibition just blew me away. I’d never seen so many beautiful paintings before.
☁️ BLOW SMOKE:
✍🏽to exaggerate or say things that aren’t true to make you seem better/ more knowledgeable than in reality
🔺I’m not blowing smoke. I have honestly read War and Peace by Tolstoy.
🐺 CRY WOLF:
✍🏽to call for help when you don’t need it
🔺Do you think Peter is in trouble or is he just crying wolf?
#sirjimmy
#teamjimmy
Show your true colours | show your true colors🎨
⌨Meaning
You show your true colours if you show what you're really like, or you reveal your true character.
🚦For example
👀Bob always acts like he's a strong, brave guy, but when the hurricane hit he showed his true colors. He was too scared to go check on old Mrs Flowers, our next-door neighbour.
👀The players showed their true colours when they came back from three goals down to win the match.
#sirjimmy
#teamjimmy
🇬🇧Popular English Idioms to Sound Like a Native Speaker
💣 BLEW ME AWAY:
✍🏽when something blows you away, you’re extremely impressed by it
🔺The exhibition just blew me away. I’d never seen so many beautiful paintings before.
☁️ BLOW SMOKE:
✍🏽to exaggerate or say things that aren’t true to make you seem better/ more knowledgeable than in reality
🔺I’m not blowing smoke. I have honestly read War and Peace by Tolstoy.
🐺 CRY WOLF:
✍🏽to call for help when you don’t need it
🔺Do you think Peter is in trouble or is he just crying wolf?
#sirjimmy
#teamjimmy
Show your true colours | show your true colors🎨
⌨Meaning
You show your true colours if you show what you're really like, or you reveal your true character.
🚦For example
👀Bob always acts like he's a strong, brave guy, but when the hurricane hit he showed his true colors. He was too scared to go check on old Mrs Flowers, our next-door neighbour.
👀The players showed their true colours when they came back from three goals down to win the match.
#sirjimmy
#teamjimmy
🌪️Negative Personality Idioms + Challenge 🎯
• 🗣️ A windbag – talks nonstop
• 🧊 A wet blanket – ruins the vibe
• 👀 A busybody / nosy parker – always in your business
• 👍 A yes-person – agrees with everything
• 😖 A pain in the neck – seriously annoying
• 🤯 A scatterbrain – forgetful and unfocused
• 👦 A mama’s boy – overly dependent
• 👐 A pushover – too easy to control
• 😈 A troublemaker – causes drama
• 💼 A social climber – status obsessed
• 🐢 A slowcoach – painfully slow
• 🗣️💬 A gossip – spreads rumors
• 🪨 A rolling stone – never settles
• 🛋️ A lazybones – super lazy
• 🎩 A stuffed shirt – too formal
• 😴 A bore – boring person
• 🧐 A snob – looks down on others
• 🚪 A gatecrasher – uninvited guest
• 🧠❌Narrow-minded – closed-off thinker
• 💔Hard-hearted –cold and cruel
• 🐖Pig-headed – stubborn AF
• 🐇Hare-brained – reckless thinker
💥Challenge:
Can you guess the idiom from the description? 🤔
1️⃣ Someone who ruins the fun at a party → ?
2️⃣ Someone who talks way too much → ?
3️⃣ Someone who is too easy to control → ?
💡 Tip: Try using one of these idioms in a sentence today! ✍️
#Idioms
#TeamJimmy
#SirJimmy
Stop and smell the roses 🌺
Meaning:
To relax; to take time out of one's busy schedule to enjoy or appreciate the beauty of life.
Example: 🌹
Slow down. Stop and smell the roses now and then.
#teamjimmy
#sirjimmy
#idioms
❌ A fast shower 🚿
✅ A quick shower
❌ Respond the door 🚪
✅ Answer the door
❌ Strong rain 🌧
✅ Heavy rain
❌ Celebrate a party 🎉
✅ Throw a party
❌ Ask for a wish 🤞🏻
✅ Make a wish
❌ Strong taste 😑
✅ Big taste
❌ Lost the time ⏳
✅ Waste time
❌ Nice dreams 🛌
✅ Sweet dreams
#sirjimmy
#teamjimmy
#idioms
🤨English Idioms Describing Character And Personality😜
✅1. Pain in the neck – an irritating, annoying person
Ex. Sarah is such a pain in the neck these days.
✅2. A people person – an outgoing person who gets along with people really well and is a good listener
Ex. Tom is enthusiastic and positive and he is a people person.
✅3. Party animal – someone who likes to attend parties often
Ex. Are you going out again tonight? You are such a party animal.
✅4. Cheapskate – a mean person who doesn’t like spending money
Ex. He was always a cheapskate even though he was earning $200,000 a year.
✅5. Happy camper – a person who is always happy and satisfied. We often use ‘happy camper’ in the negative.
Ex. The apartment was much smaller than I expected, I was not a happy camper.
✅6. Nerd – someone who is very interested in science or technology, particularly in computers
Ex. He spends all weekends at his laptop, he is such a nerd.
✅7. Life and soul of the party – someone who is energetic, and good fun during social occasions.
Ex. It was a great night, Jim was life and soul of the party.
✅8. Dipstick – a person who seems to be stupid (very informal)
Ex. I don’t know whether to laugh or be angry at his behaviour. What a complete dipstick!
✅9. Down-to-earth – someone who is practical and close to reality, who accepts other people as equals
Ex. Despite his wealth, he was a down-to-earth man. He was very generous and had a kind heart.
✅10. Early bird – a person who wakes up, arrives to work, etc. before the usual time
This expression comes from the English proverb “The early bird catches the worm”.
Ex. My Mum is the early bird in our family, she gets up at 5 o’clock in the morning.
✅11. Larger than life – someone who is more exciting or interesting than other people
Ex. All who knew him would agree that his personality was larger than life, he was a joy to be around.
#Idioms
#Teamjimmy
#sirjimmy