Когда разрабатываете свой 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
#LSK/USDT analysis :
#LSK is in a downtrend, trading below the 200 EMA and forming lower lows (LLs) and lower highs (LHs). The price is currently within a resistance zone, and it is anticipated to reverse from this level, resuming its bearish momentum to test lower price levels.
TF : 4h
Entry : $0.760
Target : $0.665
SL : $0.808
#LSK/USDT analysis :
#LSK has broken down and retested the resistance zone. The price is expected to bounce back from there and continue its bearish momentum to test the previous swing low.
TF : 4H
Entry : $0.825
Target : $0.745
SL : $0.878
📊#LSK is breakout the descending triangle with a descent volume. It got rejected from the MA 200 and currently, facing the Ichimoku cloud.✅
💬A candle close above the triangle or a break above the MA 200 would be the confirmation of a bullish rally.
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#LSK/USDT analysis -
#Lisk is experiencing a corrective pullback, creating a quick scalp opportunity on the buy side. Price is following a trendline. It is expected to bounce off from there and test the 200 EMA resistance level.
TF : 15min
Entry : $0.832
Target : $0.856
SL : $0.817
Today. I added to my experimental portfolio a coin - Lisk#LSK paired with #USDT on the Binance cryptocurrency exchange.
For me, this coin looks attractive for a long-term investment.
🛒Motives for buying#LSK
#Lisk ranks 63rd in the CoinMarketCap rating.
Good fundamental analysis is expected by the end of the year, including the halving on September 28.
The coin was not pumped!
The price is close to the resistance zone $1.6555-1.8727,
Support level is the $1.2840-1.0440.
The price projector points to a rise of $3.30.
I expect to grow from 130% to 180%.
🎯 Fibonacci 10$ experiment.