Когда разрабатываете свой 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
#QNT/USDT analysis :
#QNT is currently in a correction phase. Price is expected to decline further and test the previous swing high support level before continuing its bullish momentum. It’s advisable to wait for the price to retest the previously respected zone for a short entry, as the price is anticipated to decline and test lower levels.
TF : 1D
Entry : $126
Target : $81
SL : $156
#QNT/USDT analysis :
#QNT is currently in a downtrend, trading below the 200 EMA. The price is likely to retrace and test the resistance zone before continuing its bearish momentum. The current swing low is expected to be tested.
TF : 1H
Entry : $70.4
Target : $66.5
SL : $72.5
#QNT broken down the trendline on 12H Time frame,we expect another dump after pullback,more correction incoming..👀
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
📊#QNT price break below the $97 major support area. The last hope is the $90 support level; if the price breaks below this, we see a heavy selloff. Price needs to reclaim the $100 level to gain some positive movement. It is better to wait for some time to open new trades.⌛️
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#QNT/USDT UPDATE:
#QNT is now trading around 106$. #QNT is moving inside a symmetrical triangle on 4hr time frame. So the Possible scenarios are If the price pumps up and breaks out of the triangle, we can see bullish momentum in it. Otherwise If the price dumps and breaks down of the triangle, we can see bearish momentum in it. Stay tuned with us for further updates✔️
#Do You Know Your Crypto Logos? #XEC#QNT#BSV#ENJ#KCS#ZEC
#cryptogemtokenshttps://cryptogemtokens.com/do-you-know-your-crypto-logos-xec-qnt-bsv-enj-kcs-zec/