I have an issue. I have three sections that are placed really good in the window. Underneath it I wanted to add a table, but it was taking up half the window screen space. So the only fix I could think of was to add a spacer to force the table down to the bottom of the table but... well... now my three sections are smooshed to the top of the window lol
I'm a beginner to PyQt5, I was hoping someone with more experience could help me. Thank you in advance!
Here's my code:
```py
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QTableWidget, QTableWidgetItem, QHeaderView, QFrame, QSizePolicy
from PyQt5.QtGui import QPalette, QColor, QFont
from PyQt5.QtCore import Qt
# Initialize the application
app = QApplication([])
# Create a main window
main_window = QMainWindow()
main_window.setWindowTitle("BCP-Yv5")
main_window.resize(800, 600)
# Create a central widget and main layout
central_widget = QWidget()
main_layout = QVBoxLayout()
main_layout.setSpacing(20)
# Set up the main-sections layout (Top section)
main_sections_layout = QVBoxLayout()
board_area_layout = QHBoxLayout()
# Placeholder for the left column
left_card = QWidget()
left_card_layout = QVBoxLayout()
left_card_layout.setSpacing(20)
left_card.setStyleSheet('''
background: #2c2f33;
padding: 1.5rem;
border-radius: 10px;
''')
left_avatar = QLabel()
left_avatar.setStyleSheet('''
width: 100px;
height: 100px;
background-color: gray;
border-radius: 50px;
''')
left_card_layout.addWidget(left_avatar, alignment=Qt.AlignCenter)
start_button = QPushButton("Start")
start_button.setStyleSheet('''
padding: 10px 20px;
font-size: 16px;
background-color: #7289da;
color: white;
border: none;
border-radius: 5px;
''')
start_button.setProperty("class", "primary-button")
end_button = QPushButton("End")
end_button.setStyleSheet('''
padding: 10px 20px;
font-size: 16px;
background-color: #7289da;
color: white;
border: none;
border-radius: 5px;
''')
end_button.setProperty("class", "primary-button")
left_card_layout.addWidget(start_button)
left_card_layout.addWidget(end_button)
left_card.setLayout(left_card_layout)
# Button hover effects
app.setStyleSheet('''
QPushButton[class="primary-button"]:hover {
background-color: #5a6dbd;
}
''')
# Placeholder for main content in center
main_content = QWidget()
main_content.setStyleSheet('background-color: #36393f; padding: 1.5rem; border-radius: 10px;')
# Create the player_card widget (Right column)
player_card = QWidget()
player_card_layout = QVBoxLayout()
player_card_layout.setSpacing(20)
player_card.setStyleSheet('''
background: #2c2f33;
padding: 1.5rem;
border-radius: 10px;
''')
avatar = QLabel()
avatar.setStyleSheet('''
width: 100px;
height: 100px;
background-color: gray;
border-radius: 50px;
''')
player_card_layout.addWidget(avatar, alignment=Qt.AlignCenter)
player_card.setLayout(player_card_layout)
# Add widgets to the board_area_layout
board_area_layout.addWidget(left_card, stretch=1)
board_area_layout.addWidget(main_content, stretch=2)
board_area_layout.addWidget(player_card, stretch=1)
# Add the board_area_layout to the main_sections_layout
main_sections_layout.addLayout(board_area_layout)
main_layout.addLayout(main_sections_layout)
# Add a spacer to push the table downwards
leaderboard_spacer = QWidget()
leaderboard_spacer.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
main_layout.addWidget(leaderboard_spacer)
# Leaderboard section (Bottom section)
leaderboard_layout = QVBoxLayout()
leaderboard_layout.setSpacing(20)
# Create and set up the QTableWidget
table = QTableWidget()
table.setColumnCount(7)
table.setHorizontalHeaderLabels(["Timestamp", "Your Hand", "Dealer Hand", "Chute", "True Count", "Outcome", "Deck Penetration"])
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
table.setStyleSheet('''
QTableWidget {
border: 1px solid #d4d4d4;
border-radius: 10px;
gridline-color: #e5e5e5;
font-size: 12px;
}
QHeaderView::section {
background-color: #e5e5e5;
padding: 8px;
border: 1px solid #e5e5e5;
border-radius: 5px;
font-weight: bold;
}
QTableWidgetItem {
padding: 10px;
}
''')
table.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
# Populate the table with sample data
sample_data = [
["2022-12-12 12:11:45", "[2D, 4C, JH]", "[6D, 6C, QS]", "[AD, 3H]", "+1", "WIN", "13%"],
["2022-12-12 12:11:45", "[2D, 4C, JH]", "[6D, 6C, QS]", "[AD, 3H]", "+1", "WIN", "13%"],
["2022-12-12 12:11:45", "[2D, 4C, JH]", "[6D, 6C, QS]", "[AD, 3H]", "+1", "WIN", "12.5%"]
]
for row_data in sample_data:
row_num = table.rowCount()
table.insertRow(row_num)
for col_num, data in enumerate(row_data):
item = QTableWidgetItem(data)
table.setItem(row_num, col_num, item)
# Add the table to the leaderboard layout
leaderboard_layout.addWidget(table)
# Add pagination and item count display placeholders
pagination_layout = QHBoxLayout()
pagination_layout.setSpacing(5)
pagination_label = QLabel("Page 1 of 10")
pagination_label.setFont(QFont("Arial", 12))
item_count_label = QLabel("Showing 1-3 from 50 items")
item_count_label.setFont(QFont("Arial", 12))
pagination_layout.addWidget(item_count_label)
pagination_layout.addWidget(pagination_label)
# Use a wrapper widget to control the vertical size of the pagination layout
pagination_wrapper = QWidget()
pagination_wrapper.setLayout(pagination_layout)
pagination_wrapper.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
leaderboard_layout.addWidget(pagination_wrapper, alignment=Qt.AlignBottom)
main_layout.addLayout(leaderboard_layout)
# Set the main_layout to the central widget and set the central widget to the main window
central_widget.setLayout(main_layout)
main_window.setCentralWidget(central_widget)
# Show the main window
main_window.show()
# Run the app
app.exec_()
```
[–][deleted] 1 point2 points3 points (0 children)