@QuietWorld · Post #6230 · 12.03.2019 г., 07:12
Don’t look back and wonder why things went wrong. Don’t regret not doing more. It happened for a reason. Your better days are ahead of you. #motivation#assurance @quietworld🍃
Hashtags
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
Пребарај: #assurance
@QuietWorld · Post #6230 · 12.03.2019 г., 07:12
Don’t look back and wonder why things went wrong. Don’t regret not doing more. It happened for a reason. Your better days are ahead of you. #motivation#assurance @quietworld🍃
Hashtags
@QuietWorld · Post #6459 · 15.05.2019 г., 04:49
#assurance#selfreminder @quietworld🍃
Hashtags
@QuietWorld · Post #6864 · 05.11.2019 г., 10:23
Two years being passive is just a blink of an eye 😉 Two years moving towards a big goal every single day is plenty of time 😮 There is nothing that cannot be accomplished in two years with enough effort 😎 #life#motivation#assurance @quietworld🍃
Hashtags
@QuietWorld · Post #6231 · 12.03.2019 г., 11:15
“When it comes to breaking old habits and starting new ones, remember to be patient with yourself. You’ve got to expect it’s going to take time and effort before you see lasting results.” #quotes#assurance#motivation @quietworld🍃
Hashtags
@QuietWorld · Post #7195 · 16.02.2020 г., 10:05
#assurance#selfcare#selfreminder @quietworld🍃
Hashtags
@QuietWorld · Post #7359 · 08.06.2020 г., 03:08
to anyone who might need this at this moment🌹 #reminder#selfcare#assurance @quieworld🍃
Hashtags
@QuietWorld · Post #7223 · 21.03.2020 г., 04:07
It is not a sin to be upset; with someone, with a situation, with yourself. Give yourself time to absorb what you're feeling until you're ready to move to where there's growth. #selfreminder#selfcare#assurance#wisdom @quietworld🍃
@QuietWorld · Post #6856 · 04.11.2019 г., 13:33
Appreciate where you are in your journey, even if it's not where you want to be - because every season serves a purpose. #life#quotes#assurance#gratitude#happiness @quietworld🍃
@QuietWorld · Post #7338 · 04.06.2020 г., 15:56
Things to Remember🍃 #thingstoremember#quotes#selfreminder#selfcare#life#assurance @quietworld🍃
@QuietWorld · Post #7341 · 05.06.2020 г., 15:02
#thingstoremember#life#selfcare#selfreminder#assurance#solitude @quietworld🍃