当前位置:网站首页>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();
}
输出:

边栏推荐
- 替换license是否要重启数据库?
- 20220725 自动控制原理中的补偿器
- 基于C51实现led流水灯
- Drools (4): drools basic syntax (2)
- [arm learning (8) AXF tool analysis]
- MySQL table write lock
- Opengauss simple version installation error
- RGB-T追踪——【数据集基准】GTOT / RGBT210 / RGBT234 / VOT-2019-2020 / LasHeR / VTUAV
- 树莓派连接天猫精灵音箱通过蓝牙播放音乐的方法
- Opencv learning drawing shapes and text
猜你喜欢

MySQL execution plan

Check the top 10 best graphics software of the year, meet 99% of your chart needs, and collect it quickly

微信小程序 - 从入门到入土

Advanced Mathematics (Seventh Edition) Tongji University exercises 2-5 personal solutions

AcWing-每日一题
![[untitled] reprint](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled] reprint

Basic operations and common functions of MySQL table creation

Image annotation software reference

Opencv learning drawing shapes and text
![[arm learning (8) AXF tool analysis]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[arm learning (8) AXF tool analysis]
随机推荐
MySQL check whether the table is locked
Docker modifying the MySQL configuration file attached to the host does not take effect?
Intention lock
mySql建表的基本操作 与常见的函数
20220725 convolution in automatic control principle
The method of raspberry pie connecting tmall elf speaker to play music through Bluetooth
Linux c SQLite database usage
Weekly tip 142: multi parameter constructors and explicit
Opencv learning warp Perspective
Opencv learn read images videos and webcams
解决 Chrome 浏览器被毒霸篡改问题
SQL shell (PSQL) tool under PostgreSQL
Exclusive lock
Drools (3): drools basic syntax (1)
【硬十宝典】——7.2【动态RAM】DDR4与DDR3区别解析
Analysis of strong tennis cup 2021 PWN competition -- baby_ diary
Realization of LED water lamp based on C51
Curl post request on the server, using postman tool for parameter conversion
IDEA——使用@Slf4j打印日志
NiO implementation