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

Резултати

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

Пребарај: #davidwatkyns

当前筛选 #davidwatkyns清除筛选

🎶 Дэвид Уоткинс «Рождество в Кейптауне» 🎄 _____________ 🎶David Watkyns Christmas in Cape Town🎄 Christmas In Cape Town You won’t see any snowfall At this time of year No reindeer in the valley As the mistletoe appears And underneath the blue sky Is a perfect summer’s day with beaches filled with people All the beauty on display Cause when it's Christmas in Cape Town There's happiness and joy And smiles upon the faces Of every boy and girl The sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place to be Take a walk on Table Mountain Or on the grand parade And we’ll see the minstrels dancing With an umbrella for shade In the night-time there’ll be music New people you can meet And the lights will shine down brightly All the way down Adderley Street And there’s not another place I’d rather be Cause when it's Christmas in Cape Town There's happiness and joy And smiles upon the faces Of every boy and girl The sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place to be When it's Christmas in Cape Town There's happiness and joy And smiles upon the faces Of every boy and girl The sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place to be, to be And the sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place for me 📹https://www.youtube.com/watch?v=_Zr_Ub94muk #Christmas#SouthAfrica#Capetown#DavidWatkyns#Music

🎶 Дэвид Уоткинс «Рождество в Кейптауне» 🎄 _____________ 🎶David Watkyns Christmas in Cape Town🎄 Christmas In Cape Town You won’t see any snowfall At this time of year No reindeer in the valley As the mistletoe appears And underneath the blue sky Is a perfect summer’s day with beaches filled with people All the beauty on display Cause when it's Christmas in Cape Town There's happiness and joy And smiles upon the faces Of every boy and girl The sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place to be Take a walk on Table Mountain Or on the grand parade And we’ll see the minstrels dancing With an umbrella for shade In the night-time there’ll be music New people you can meet And the lights will shine down brightly All the way down Adderley Street And there’s not another place I’d rather be Cause when it's Christmas in Cape Town There's happiness and joy And smiles upon the faces Of every boy and girl The sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place to be When it's Christmas in Cape Town There's happiness and joy And smiles upon the faces Of every boy and girl The sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place to be, to be And the sun is shining brightly Over mountains and the seas When it’s Christmas in Cape Town It’s a special place for me 📹https://www.youtube.com/watch?v=_Zr_Ub94muk #Christmas#SouthAfrica#Capetown#DavidWatkyns#Music