当前位置:网站首页>Qt:列表框、表格、树形控件
Qt:列表框、表格、树形控件
2022-07-26 07:10:00 【@布响丸辣】
一、列表框
#include "widget.h"
#include <QApplication>
#include <QListWidget>
#include <QStringList>
#include <QTableWidget>
#include <QTreeWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
QListWidget lw(&w);
lw.move(100,200);
lw.resize(100,200);
lw.addItem("百度");
lw.addItem(new QListWidgetItem("腾讯"));
QStringList qstr;
qstr << "阿里巴巴" << "字节跳动" ;
lw.addItems(QStringList() << "阿里巴巴" << "字节跳动");
QObject::connect(&lw,&QListWidget::itemDoubleClicked,&lw,&QListWidget::clear);
w.show();
return a.exec();
}
输出:

二、表格
#include "widget.h"
#include <QApplication>
#include <QListWidget>
#include <QStringList>
#include <QTableWidget>
#include <QTreeWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
QTableWidget tw(3,3,&w);
tw.move(100,100);
tw.resize(500,400);
tw.setHorizontalHeaderLabels(QStringList() << "企业" << "网址" << "创始人");
tw.setItem(0,0,new QTableWidgetItem("百度"));
tw.setItem(0,1,new QTableWidgetItem("www.baidu.com"));
tw.setItem(0,2,new QTableWidgetItem("李彦宏"));
tw.setItem(1,0,new QTableWidgetItem("腾讯"));
tw.setItem(1,1,new QTableWidgetItem("www.qq.com"));
tw.setItem(1,2,new QTableWidgetItem("马化腾"));
tw.setItem(2,0,new QTableWidgetItem("阿里巴巴"));
tw.setItem(2,1,new QTableWidgetItem("www.1688.com"));
tw.setItem(2,2,new QTableWidgetItem("马云"));
tw.setRowCount(tw.rowCount() + 1);
tw.setItem(3,0,new QTableWidgetItem("字节跳动"));
tw.setItem(3,1,new QTableWidgetItem("www.bytedance.com"));
tw.setItem(3,2,new QTableWidgetItem("张一鸣"));
QObject::connect(&tw,&QTableWidget::cellDoubleClicked,&tw,&QTableWidget::removeRow);
w.show();
return a.exec();
}输出:

三、树形控件
#include "widget.h"
#include <QApplication>
#include <QListWidget>
#include <QStringList>
#include <QTableWidget>
#include <QTreeWidget>
tw.move(100,100);
tw.resize(300,200);
QTreeWidgetItem topItem(&tw);
topItem.setText(0,"网址");
//tw.addTopLevelItem(&topItem);
QTreeWidgetItem Bd(&topItem,QStringList() << "百度");
QTreeWidgetItem BdUrl(&Bd,QStringList() << "www.baidu.com");
QTreeWidgetItem Tx(&topItem,QStringList() << "腾讯");
QTreeWidgetItem TxUrl(&Tx,QStringList() << "www.qq.com");
w.show();
return a.exec();
}
输出:

边栏推荐
- “蔚来杯“2022牛客暑期多校训练营1补题记录(ACDGIJ)
- Common programming shortcut keys of idea (take off after learning the operation)
- mySql建表的基本操作 与常见的函数
- [749. Isolate virus]
- 在第一次使用德国小鸡要注意的地方
- Shared lock
- npm 命令
- [today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal
- NiO implementation
- Hands on practice - teach you how to make an intelligent fish tank with STM32
猜你喜欢

Is the passenger flow always low? There is something wrong with the location of your store!

Precious metal knowledge: lethal short-term secret script

【一库】妙啊!这个库组织npm脚本简直爆炸!

String and memory functions

Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !

The results of the soft test can be checked, and the entry to query the results of the soft test has been opened in the first half of 2022

Yolov6 target detection practice: training your own data set (video tutorial)

Wechat applet - from entry to penetration

Hands on practice - teach you how to make an intelligent fish tank with STM32

Leetcode question brushing 1: topic classification
随机推荐
Common CMD instructions
Curl post request on the server, using postman tool for parameter conversion
Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
buuReserve(4)
Summarize and learn STM32 to create project template
opengauss简易版安装报错
Performance test -- lockust performs seckill business scenario test
Question: can't download sh shellcheck Please install it manually and some commands of shell script
How to use Hyper-V in win10 Home Edition
MySQL execution plan
Why can't extern compile variables decorated with const?
Deep learning learning notes -- solve the problem of slow download of CONDA and pip
Manifest merger failed with multiple errors, see logs
问题:Can‘t download sh shellcheck. Please install it manually及shell脚本的一些命令使用
【硬十宝典】——7.2【动态RAM】DDR4与DDR3区别解析
MySql 执行计划
Overview of new features of es11, ES12 and es13
[arm learning (8) AXF tool analysis]
常用的cmd指令
Opencv learning drawing shapes and text