当前位置:网站首页>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
边栏推荐
- 2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
- Go's gin framework learning
- Write a regular
- Kubernetes 服务发现 监控Endpoints
- .104History
- 【Appium】通过设计关键字驱动文件来编写脚本
- Halo open source project learning (II): entity classes and data tables
- Land cover / use data product download
- Implementation of k8s redis one master multi slave dynamic capacity expansion
- In JS, t, = > Analysis of
猜你喜欢
102. Sequence traversal of binary tree
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
Remember using Ali Font Icon Library for the first time
Halo open source project learning (II): entity classes and data tables
C1 notes [task training part 2]
.105Location
Uniapp custom search box adaptation applet alignment capsule
Gets the time range of the current week
Operators in C language
随机推荐
Write a regular
SystemVerilog (VI) - variable
Halo open source project learning (II): entity classes and data tables
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
Transfer learning of five categories of pictures based on VGg
Leak detection and vacancy filling (6)
Add animation to the picture under V-for timing
ES6 face test questions (reference documents)
20222 return to the workplace
Implementation of k8s redis one master multi slave dynamic capacity expansion
EasymodbusTCP之clientexample解析
How to read literature
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]
Listen for click events other than an element
Vite configure proxy proxy to solve cross domain
Cloud native Virtualization: building edge computing instances based on kubevirt
198. Looting - Dynamic Planning
Romance in C language
Go's gin framework learning
.105Location