Created
January 12, 2020 15:38
-
-
Save FloydanTheBeast/a726df22b3b8eaa569dd69cf7be808b7 to your computer and use it in GitHub Desktop.
PyQt stylesheets example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QVBoxLayout | |
app = QApplication([]) | |
window = QWidget() | |
# Применение стилей напрямую к элементу | |
window.setStyleSheet('background-color: #0E171E') | |
layout = QVBoxLayout() | |
btn = QPushButton('Кнопка') | |
# Применение стилей по классу | |
btn.setStyleSheet('QPushButton { padding: 2ex; background-color: #1E272E; color: #FFF; border-radius: 8px; } \ | |
QPushButton:hover { background-color: #3E474E;}') | |
label1 = QLabel('Обычный текст') | |
label2 = QLabel('Кастомный текст') | |
label2.setObjectName('danger') | |
# Примененение стилей по названию | |
app.setStyleSheet('QLabel { color: #FFF; font-size: 16px } QLabel#danger { color: red; font-weight: 800 }') | |
layout.addWidget(label1) | |
layout.addWidget(label2) | |
layout.addWidget(btn) | |
window.setLayout(layout) | |
window.resize(400, 200) | |
window.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment