QTablewidget style setting in QT

Table of contents

1. Hide the horizontal and vertical scroll bars of the tablewidget

 2. Set the table to scroll automatically

 3. Set the table to select the entire row

 4. Hide the Grid

 5. Hide the vertical header

 6. Set the header style and table background to be transparent


Use QTablewidget as a table in the QT project to modify the table style. This article records the property settings of tbalewidget. The following setting methods are all set in the property sheet, and these settings can also be implemented with code in the .cpp file.

1. Hide the horizontal and vertical scroll bars of the tablewidget

Select the tablewidget in the ui, and then set the vertical scroll bar to off: verticalScrollBarPolicy->ScrollBarAlwaysOff, and the horizontal scroll bar to off: horizontalScrollBarPolicy->ScrollBarAlwaysOff.

 2. Set the table to scroll automatically

After creating a tablewidget, the table is automatically scrolled by default

 3. Set the table to select the entire row

Select the tablewidget in ui, then set selectionBehavior->selectRows

 4. Hide the Grid

 5. Hide the vertical header

 6. Set the header style and table background to be transparent

//设置表格列宽
for(int i = 0;i<4;i++)
{
    ui->tableWidget->setColumnWidth(i, 100);
}
//设置表格背景透明
ui->tableWidget->setStyleSheet("background-color: transparent;");
ui->tableWidget->setAttribute(Qt::WA_TranslucentBackground, true);
//设置表头样式
ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color:transparent;font:13pt '黑体';color: rgb(57,233,235);}");

Effect:

 

Guess you like

Origin blog.csdn.net/weixin_55735677/article/details/130239740