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
|
||||
|
||||
|
||||
@@ -13,3 +13,16 @@ class Button(QPushButton):
|
||||
self.setFont(font)
|
||||
self.setMinimumSize(75, 75)
|
||||
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
|
||||
|
||||
from buttons import Button
|
||||
from buttons import Button, ButtonsGrid
|
||||
from display import Display
|
||||
from info import Info
|
||||
from main_window import MainWindow
|
||||
@@ -22,17 +22,15 @@ if __name__ == '__main__':
|
||||
|
||||
# Info
|
||||
info = Info('2.0 ^ 10.0 = 1024')
|
||||
window.addToVLayout(info)
|
||||
window.addWidgetToVLayout(info)
|
||||
|
||||
# Display
|
||||
display = Display()
|
||||
window.addToVLayout(display)
|
||||
window.addWidgetToVLayout(display)
|
||||
|
||||
button = Button('Texto do botão')
|
||||
window.addToVLayout(button)
|
||||
|
||||
button2 = Button('Texto do botão')
|
||||
window.addToVLayout(button2)
|
||||
# Grid
|
||||
buttonsGrid = ButtonsGrid()
|
||||
window.vLayout.addLayout(buttonsGrid)
|
||||
|
||||
# Executa tudo
|
||||
window.adjustFixedSize()
|
||||
|
||||
@@ -19,5 +19,5 @@ class MainWindow(QMainWindow):
|
||||
self.adjustSize()
|
||||
self.setFixedSize(self.width(), self.height())
|
||||
|
||||
def addToVLayout(self, widget: QWidget):
|
||||
def addWidgetToVLayout(self, widget: QWidget):
|
||||
self.vLayout.addWidget(widget)
|
||||
|
||||
Reference in New Issue
Block a user