在这里,我想增加headerlabel的行高和单元格项目的字体大小。在我的代码中,我使用的是self.table.setRowHeight()
方法,但是它不起作用。因此,请告诉我他们是增加页眉标签的行高和单元格字体大小的任何方法。
给出以下是我的代码:
import sys
from PyQt4 import QtGui, QtCore
ROUNDED_STYLE_SHEET1 = """QPushButton {
background-color: green;
color: white;
border-style: outset;
border-width: 4px;
border-radius: 15px;
border-color: none;
font: bold 12px;
min-width: 10em;
padding: 10px;
}
"""
OVAL = """QPushButton {
position: relative;
width: 50px;
height: 30px;
margin: 20px 0;
background: blue;
border-radius: 48% / 25%;
color: white;
font: bold 10px;
}
"""
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.label = QtGui.QLabel("Invoice Serial Number-39",self)
self.label.setStyleSheet("font: bold 20pt AGENTORANGE")
self.label.move(10,20)
self.line_edit = QtGui.QLineEdit(self)
self.line_edit.move(900,15)
self.line_edit.resize(300,30)
self.btn1 = QtGui.QPushButton("connect",self)
self.btn1.setStyleSheet(ROUNDED_STYLE_SHEET1)
self.btn1.move(1200,10)
self.btn2 =QtGui.QPushButton("back", self)
self.btn2.move(70,200)
self.btn3 = QtGui.QPushButton("Reset Form", self)
self.btn3.move(140,200)
self.btn3.setStyleSheet("background-color:brown")
self.btn4 = QtGui.QPushButton("pay", self)
self.btn4.setStyleSheet(OVAL)
self.btn4.move(1200,170)
self. table = QtGui.QTableWidget(self)
self.table.move(10,70)
self.table.resize(1350,100)
self.table_item = QtGui.QTableWidgetItem()
self.table.setRowCount(1)
self.table.setColumnCount(6)
self.tbutton = QtGui.QToolButton()
self.tbutton.setToolTip("delete")
self.tbutton.setIcon(QtGui.QIcon("trash1.png"))
self.tbutton.setCheckable(True)
self.qspinbox = QtGui.QSpinBox()
self.qspinbox.setMinimum(1)
self.qspinbox.setMaximum(50)
self.qspinbox.setRange(1,50)
self.qspinbox.setMinimum(1)
self.table.setHorizontalHeaderLabels(("S.no, Item Description,Qty,Rate(Rs:),Subtotal,"",").split(','))
self.table.setVerticalHeaderLabels(("1").split(','))
self.table.setItem(0,0,QtGui.QTableWidgetItem("1"))
self.table.setItem(0,1, QtGui.QTableWidgetItem("Acne-aid Wash Facial Cleansing"))
self.table.setItem(0,2,QtGui.QTableWidgetItem("1"))
self.table.setItem(0,3,QtGui.QTableWidgetItem("191.72"))
self.table.setItem(0,4,QtGui.QTableWidgetItem("191.72"))
self.table.setItem(0,5,QtGui.QTableWidgetItem(""))
self.table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.table.setCellWidget(0,5,self.tbutton)
self.table.setCellWidget(0,2,self.qspinbox)
self.table.horizontalHeader().setStyleSheet("QHeaderView { font-size: 18pt};")
self.table.horizontalHeader().setStyleSheet("::section {background-color : lightGray;font-size:10pt;}")
self.table.setRowHeight(0,100)
self.table.horizontalHeader().setStretchLastSection(True)
self.table.setStyleSheet("QTableWidget{ width:100%; height: 100px; }")
self.table.setColumnWidth(0,100)
self.table.resizeRowsToContents()
self.table.setColumnWidth(1,250)
self.table.setColumnWidth(2,300)
self.table.setColumnWidth(3,250)
self.table.setColumnWidth(4,250)
self.table.setColumnWidth(5,200)
self.btn4.clicked.connect(self.on_pushButton_clicked)
# self.dialog = Example1()
self.setWindowTitle("business management")
self.setGeometry(200,300,900,600)
self.showMaximized()
def on_pushButton_clicked(self):
self.dialog.showMaximized()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
ex.setStyleSheet("background-color:white")
if __name__ == '__main__':
main()
最佳答案
如果要增加水平标题的高度,则必须使用setFixedHeight()
,例如:
self.table.horizontalHeader().setFixedHeight(60)
如果要增加单元格的字体,则必须设置
setFont()
的QTableWidget
方法:fnt = self.table.font()
fnt.setPointSize(40)
self.table.setFont(fnt)
关于python - 如何在pyqt4中增加QTableWidget中标题标签的行高和行项目的字体大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52089202/