Created
July 17, 2021 16:22
-
-
Save MaurizioB/faedf525b4beb8910d3d25ebff66b984 to your computer and use it in GitHub Desktop.
QPushButton with embedded QLabel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5 import QtWidgets | |
import sys | |
app = QtWidgets.QApplication(sys.argv) | |
window = QtWidgets.QWidget() | |
mainLayout = QtWidgets.QGridLayout(window) | |
labels = [] | |
for r in range(3): | |
for c in range(4): | |
button = QtWidgets.QPushButton() | |
label = QtWidgets.QLabel() | |
# possible workaround: | |
# button.sizeHint = label.sizeHint | |
mainLayout.addWidget(button, r, c) | |
button.setStyleSheet('QPushButton {border: none;}') | |
buttonLayout = QtWidgets.QVBoxLayout(button) | |
buttonLayout.setContentsMargins(0, 0, 0, 0) | |
labels.append(label) | |
buttonLayout.addWidget(label) | |
le = QtWidgets.QLineEdit(placeholderText='button text') | |
mainLayout.addWidget(le, mainLayout.rowCount(), 0, 1, 4) | |
le.textChanged.connect(lambda text: [l.setText(text) for l in labels]) | |
window.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment