如何在pyqt4中增加QTableWidget中标题标签的行高和行项的字体大小 [英] how to increase the row height of the header labels and font size of the row items in QTableWidget in pyqt4

查看:255
本文介绍了如何在pyqt4中增加QTableWidget中标题标签的行高和行项的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我想增加单元格项的标题标签的行高和字体大小.在我的代码中,我使用 self.table.setRowHeight() 方法,但它不起作用.所以请告诉我他们有什么方法可以增加标题标签的行高和单元格项目的字体大小.

Here i want to increase the row height of the headerlabel and font size of the cell items. In my code I am using self.table.setRowHeight() method, but its not working. So please tell me is their any method to increase the row height of the header labels and font size of cell items.

下面是我的代码:

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(),例如:

If you want to increase the height of the horizontal header you must use setFixedHeight(), for example:

self.table.horizontalHeader().setFixedHeight(60)

如果要增加单元格的字体,必须设置QTableWidgetsetFont()方法:

If you want to increase the font of the cells you must set the setFont() method of the QTableWidget:

fnt = self.table.font()
fnt.setPointSize(40)
self.table.setFont(fnt)

这篇关于如何在pyqt4中增加QTableWidget中标题标签的行高和行项的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆