Пишу "Морской бой" и при изменение разрешения экрана игры таблица становиться маленькой, как сделать так что бы таблица автоматически подстраивалась под рамки tableWidget?
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, \
QStackedWidget
from PyQt5 import QtCore, QtGui, QtWidgets
SCREEN_SIZE = [(960, 540), (1280, 720), (1920, 1080)]
class Ui_table_add(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(978, 578)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(10)
font.setItalic(False)
font.setStrikeOut(False)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.verticalLayout_2.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(10)
font.setItalic(False)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.verticalLayout_2.addWidget(self.pushButton_2)
self.gridLayout.addLayout(self.verticalLayout_2, 0, 1, 1, 1)
self.boardMap = QtWidgets.QTableWidget(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.boardMap.setFont(font)
self.boardMap.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.boardMap.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored)
self.boardMap.setObjectName("boardMap")
self.boardMap.setColumnCount(10)
self.boardMap.setRowCount(10)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(7, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(8, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setVerticalHeaderItem(9, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(7, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(8, item)
item = QtWidgets.QTableWidgetItem()
self.boardMap.setHorizontalHeaderItem(9, item)
self.gridLayout.addWidget(self.boardMap, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 978, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "1 разришение 960 на 540"))
self.pushButton_2.setText(_translate("MainWindow", "2 разришение 1280 на 720"))
item = self.boardMap.verticalHeaderItem(0)
item.setText(_translate("MainWindow", "1"))
item = self.boardMap.verticalHeaderItem(1)
item.setText(_translate("MainWindow", "2"))
item = self.boardMap.verticalHeaderItem(2)
item.setText(_translate("MainWindow", "3"))
item = self.boardMap.verticalHeaderItem(3)
item.setText(_translate("MainWindow", "4"))
item = self.boardMap.verticalHeaderItem(4)
item.setText(_translate("MainWindow", "5"))
item = self.boardMap.verticalHeaderItem(5)
item.setText(_translate("MainWindow", "6"))
item = self.boardMap.verticalHeaderItem(6)
item.setText(_translate("MainWindow", "7"))
item = self.boardMap.verticalHeaderItem(7)
item.setText(_translate("MainWindow", "8"))
item = self.boardMap.verticalHeaderItem(8)
item.setText(_translate("MainWindow", "9"))
item = self.boardMap.verticalHeaderItem(9)
item.setText(_translate("MainWindow", "10"))
item = self.boardMap.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "A"))
item = self.boardMap.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "B"))
item = self.boardMap.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "C"))
item = self.boardMap.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "D"))
item = self.boardMap.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "E"))
item = self.boardMap.horizontalHeaderItem(5)
item.setText(_translate("MainWindow", "F"))
item = self.boardMap.horizontalHeaderItem(6)
item.setText(_translate("MainWindow", "G"))
item = self.boardMap.horizontalHeaderItem(7)
item.setText(_translate("MainWindow", "H"))
item = self.boardMap.horizontalHeaderItem(8)
item.setText(_translate("MainWindow", "I"))
item = self.boardMap.horizontalHeaderItem(9)
item.setText(_translate("MainWindow", "J"))
class Start(QMainWindow, Ui_table_add):
def __init__(self, parent=None):
super(Start, self).__init__(parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.screen_resolution)
self.pushButton_2.clicked.connect(self.screen_resolution1)
def screen_resolution(self):
windows.resize(*SCREEN_SIZE[0])
def screen_resolution1(self):
windows.resize(*SCREEN_SIZE[1])
if __name__ == '__main__':
app = QApplication(sys.argv)
startmenu_window = Start()
windows = QStackedWidget()
windows.addWidget(startmenu_window)
windows.show()
sys.exit(app.exec_())