当前位置:网站首页>Qtablewidget usage explanation
Qtablewidget usage explanation
2022-04-23 17:56:00 【liu_ jie_ bin】
QTableWidget brief introduction
QTableWidget Class provides an item based table view with a default model .Table Widgets provide standard display tools for applications .QTableWidget Items in by QTableWidgetItem Provide .
effect
.h file
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_btnAdd_clicked();
void on_btnClear_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
.ccp file
#include "widget.h"
#include "ui_widget.h"
#include<QSpinBox>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->comboBox->addItem(QStringLiteral(" male "));
ui->comboBox->addItem(QStringLiteral(" Woman "));
// Set number of columns
ui->tableWidget->setColumnCount(3);
// Set the number of lines
//ui->tableWidget->setRowCount(15);
// Set the vertical header invisible
ui->tableWidget->verticalHeader()->setVisible(false);
// For header title QStringList To express
QStringList headerText;
headerText<<QStringLiteral(" name ")<<QStringLiteral(" Gender ")<<QStringLiteral(" Age ");
ui->tableWidget->setHorizontalHeaderLabels(headerText);
// Settings are not editable
ui->tableWidget->setEditTriggers(QTableWidget::NoEditTriggers);
// Set the selected full line mode
ui->tableWidget->setSelectionBehavior(QTableWidget::SelectRows);
// Set radio mode
ui->tableWidget->setSelectionMode(QTableWidget::SingleSelection);
// Turn on alternate line background color
ui->tableWidget->setAlternatingRowColors(true);
// Set content adaptive width
//ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// Set the adaptive length of the last column
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
// Set header style
ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{padding:3px; margin:0px; color:#DCDCDC; border:1px solid #242424; \ border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px; \ background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252);}");
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_btnAdd_clicked()
{
// Get the number of lines
int rowCount = ui->tableWidget->rowCount();
// Insert row
ui->tableWidget->insertRow(rowCount);
// Add child QSpinBox
QSpinBox *ages = new QSpinBox();
ages->setValue(24);
ui->tableWidget->setCellWidget(rowCount,2, ages);
QString strName = ui->lineEdit->text();
// Add name child
QTableWidgetItem *nameItem = new QTableWidgetItem(strName);
// Set individual item attribute
nameItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QFont font = nameItem->font();
font.setBold(true);
nameItem->setTextColor(QColor(0,0,255));
// add to
ui->tableWidget->setItem(rowCount,0,nameItem);
// Add sex sub item
QString strSex = ui->comboBox->currentText();
// Set individual item attribute
QTableWidgetItem *sexItem = new QTableWidgetItem(strSex);
sexItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
sexItem->setTextColor(QColor(255,0,0));
// add to
ui->tableWidget->setItem(rowCount,1,sexItem);
}
void Widget::on_btnClear_clicked()
{
ui->tableWidget->clearContents();
ui->tableWidget->setRowCount(0);
}
ui Layout
版权声明
本文为[liu_ jie_ bin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231752142884.html
边栏推荐
- Leak detection and vacancy filling (VII)
- Amount input box, used for recharge and withdrawal
- C language array processing batch data
- 2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
- Go对文件操作
- 239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
- 1217_ Generating target files using scons
- Arithmetic expression
- Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
- SystemVerilog(六)-变量
猜你喜欢
.105Location
Comparison between xtask and kotlin coroutine
Cloud native Virtualization: building edge computing instances based on kubevirt
92. Reverse linked list II byte skipping high frequency question
Cross domain settings of Chrome browser -- including new and old versions
Go语言JSON包使用
MySQL 中的字符串函数
Transfer learning of five categories of pictures based on VGg
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
EasymodbusTCP之clientexample解析
随机推荐
Special effects case collection: mouse planet small tail
JS forms the items with the same name in the array object into the same array according to the name
An example of linear regression based on tensorflow
2021长城杯WP
Element calculation distance and event object
Gaode map search, drag and drop query address
C# 网络相关操作
C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
Eigen learning summary
209. Minimum length subarray - sliding window
Future usage details
Utilisation de la liste - Ajouter, supprimer et modifier la requête
JS high frequency interview questions
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Gets the time range of the current week
ES6 face test questions (reference documents)
MySQL advanced index [classification, performance analysis, use, design principles]
Commonly used functions -- spineros:: and spineros::)
Halo open source project learning (II): entity classes and data tables
198. Looting - Dynamic Planning