Calculadora: grid de botões com QGridLayout (parte 1)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from PySide6.QtWidgets import QPushButton
|
from PySide6.QtWidgets import QGridLayout, QPushButton
|
||||||
from variables import MEDIUM_FONT_SIZE
|
from variables import MEDIUM_FONT_SIZE
|
||||||
|
|
||||||
|
|
||||||
@@ -13,3 +13,16 @@ class Button(QPushButton):
|
|||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.setMinimumSize(75, 75)
|
self.setMinimumSize(75, 75)
|
||||||
self.setProperty('cssClass', 'specialButton')
|
self.setProperty('cssClass', 'specialButton')
|
||||||
|
|
||||||
|
|
||||||
|
class ButtonsGrid(QGridLayout):
|
||||||
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self._grid_mask = [
|
||||||
|
['C', '◀', '^', '/'],
|
||||||
|
['7', '8', '9', '*'],
|
||||||
|
['4', '5', '6', '-'],
|
||||||
|
['1', '2', '3', '+'],
|
||||||
|
['', '0', '.', '='],
|
||||||
|
]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from buttons import Button
|
from buttons import Button, ButtonsGrid
|
||||||
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
|
||||||
@@ -22,17 +22,15 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Info
|
# Info
|
||||||
info = Info('2.0 ^ 10.0 = 1024')
|
info = Info('2.0 ^ 10.0 = 1024')
|
||||||
window.addToVLayout(info)
|
window.addWidgetToVLayout(info)
|
||||||
|
|
||||||
# Display
|
# Display
|
||||||
display = Display()
|
display = Display()
|
||||||
window.addToVLayout(display)
|
window.addWidgetToVLayout(display)
|
||||||
|
|
||||||
button = Button('Texto do botão')
|
# Grid
|
||||||
window.addToVLayout(button)
|
buttonsGrid = ButtonsGrid()
|
||||||
|
window.vLayout.addLayout(buttonsGrid)
|
||||||
button2 = Button('Texto do botão')
|
|
||||||
window.addToVLayout(button2)
|
|
||||||
|
|
||||||
# Executa tudo
|
# Executa tudo
|
||||||
window.adjustFixedSize()
|
window.adjustFixedSize()
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ class MainWindow(QMainWindow):
|
|||||||
self.adjustSize()
|
self.adjustSize()
|
||||||
self.setFixedSize(self.width(), self.height())
|
self.setFixedSize(self.width(), self.height())
|
||||||
|
|
||||||
def addToVLayout(self, widget: QWidget):
|
def addWidgetToVLayout(self, widget: QWidget):
|
||||||
self.vLayout.addWidget(widget)
|
self.vLayout.addWidget(widget)
|
||||||
|
|||||||
Reference in New Issue
Block a user