Calculadora: criando um botão com QPushButton no PySide6
This commit is contained in:
15
aula202-calculadora/buttons.py
Normal file
15
aula202-calculadora/buttons.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from PySide6.QtWidgets import QPushButton
|
||||||
|
from variables import MEDIUM_FONT_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
class Button(QPushButton):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.configStyle()
|
||||||
|
|
||||||
|
def configStyle(self):
|
||||||
|
font = self.font()
|
||||||
|
font.setPixelSize(MEDIUM_FONT_SIZE)
|
||||||
|
self.setFont(font)
|
||||||
|
self.setMinimumSize(75, 75)
|
||||||
|
self.setProperty('cssClass', 'specialButton')
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from buttons import Button
|
||||||
from display import Display
|
from display import Display
|
||||||
from info import Info
|
from info import Info
|
||||||
from main_window import MainWindow
|
from main_window import MainWindow
|
||||||
@@ -27,6 +28,12 @@ if __name__ == '__main__':
|
|||||||
display = Display()
|
display = Display()
|
||||||
window.addToVLayout(display)
|
window.addToVLayout(display)
|
||||||
|
|
||||||
|
button = Button('Texto do botão')
|
||||||
|
window.addToVLayout(button)
|
||||||
|
|
||||||
|
button2 = Button('Texto do botão')
|
||||||
|
window.addToVLayout(button2)
|
||||||
|
|
||||||
# Executa tudo
|
# Executa tudo
|
||||||
window.adjustFixedSize()
|
window.adjustFixedSize()
|
||||||
window.show()
|
window.show()
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ from variables import (DARKER_PRIMARY_COLOR, DARKEST_PRIMARY_COLOR,
|
|||||||
PRIMARY_COLOR)
|
PRIMARY_COLOR)
|
||||||
|
|
||||||
qss = f"""
|
qss = f"""
|
||||||
PushButton[cssClass="specialButton"] {{
|
QPushButton[cssClass="specialButton"] {{
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: {PRIMARY_COLOR};
|
background: {PRIMARY_COLOR};
|
||||||
}}
|
}}
|
||||||
PushButton[cssClass="specialButton"]:hover {{
|
QPushButton[cssClass="specialButton"]:hover {{
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: {DARKER_PRIMARY_COLOR};
|
background: {DARKER_PRIMARY_COLOR};
|
||||||
}}
|
}}
|
||||||
PushButton[cssClass="specialButton"]:pressed {{
|
QPushButton[cssClass="specialButton"]:pressed {{
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: {DARKEST_PRIMARY_COLOR};
|
background: {DARKEST_PRIMARY_COLOR};
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user