Qt控件(按钮、单选、复选、list、tree、table)

news2024/9/28 13:18:59

 一、布局

工具栏图标文字一起显示,背景透明。

 

  二、代码

widget.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Widget</class>
 <widget class="QWidget" name="Widget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Widget</string>
  </property>
  <widget class="QPushButton" name="pushButton">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>10</y>
     <width>75</width>
     <height>23</height>
    </rect>
   </property>
   <property name="text">
    <string>登录</string>
   </property>
  </widget>
  <widget class="QToolButton" name="toolButton">
   <property name="geometry">
    <rect>
     <x>100</x>
     <y>10</y>
     <width>91</width>
     <height>21</height>
    </rect>
   </property>
   <property name="text">
    <string>工具</string>
   </property>
   <property name="icon">
    <iconset resource="res.qrc">
     <normaloff>:/icon/demo01.png</normaloff>:/icon/demo01.png</iconset>
   </property>
   <property name="toolButtonStyle">
    <enum>Qt::ToolButtonTextBesideIcon</enum>
   </property>
   <property name="autoRaise">
    <bool>true</bool>
   </property>
  </widget>
  <widget class="QGroupBox" name="groupBox">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>50</y>
     <width>120</width>
     <height>80</height>
    </rect>
   </property>
   <property name="title">
    <string>性别</string>
   </property>
   <widget class="QRadioButton" name="rBtnMan">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>20</y>
      <width>95</width>
      <height>19</height>
     </rect>
    </property>
    <property name="text">
     <string>男</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="rBtnWoman">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>50</y>
      <width>95</width>
      <height>19</height>
     </rect>
    </property>
    <property name="text">
     <string>女</string>
    </property>
   </widget>
  </widget>
  <widget class="QGroupBox" name="groupBox_2">
   <property name="geometry">
    <rect>
     <x>170</x>
     <y>50</y>
     <width>120</width>
     <height>54</height>
    </rect>
   </property>
   <property name="title">
    <string>婚否</string>
   </property>
   <layout class="QHBoxLayout" name="horizontalLayout">
    <item>
     <widget class="QRadioButton" name="radioButton_4">
      <property name="text">
       <string>未婚</string>
      </property>
     </widget>
    </item>
    <item>
     <widget class="QRadioButton" name="radioButton_3">
      <property name="text">
       <string>已婚</string>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QGroupBox" name="groupBox_3">
   <property name="geometry">
    <rect>
     <x>320</x>
     <y>20</y>
     <width>100</width>
     <height>141</height>
    </rect>
   </property>
   <property name="title">
    <string>问卷调查</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QCheckBox" name="checkBox_4">
      <property name="text">
       <string>价格实惠</string>
      </property>
     </widget>
    </item>
    <item>
     <widget class="QCheckBox" name="checkBox">
      <property name="text">
       <string>口感好</string>
      </property>
     </widget>
    </item>
    <item>
     <widget class="QCheckBox" name="checkBox_3">
      <property name="text">
       <string>服务到位</string>
      </property>
     </widget>
    </item>
    <item>
     <widget class="QCheckBox" name="cBox">
      <property name="text">
       <string>老板好</string>
      </property>
      <property name="tristate">
       <bool>true</bool>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QListWidget" name="listWidget">
   <property name="geometry">
    <rect>
     <x>480</x>
     <y>20</y>
     <width>256</width>
     <height>171</height>
    </rect>
   </property>
  </widget>
  <widget class="QTreeWidget" name="treeWidget">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>200</y>
     <width>256</width>
     <height>192</height>
    </rect>
   </property>
   <column>
    <property name="text">
     <string notr="true">1</string>
    </property>
   </column>
  </widget>
  <widget class="QTableWidget" name="tableWidget">
   <property name="geometry">
    <rect>
     <x>290</x>
     <y>200</y>
     <width>451</width>
     <height>192</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources>
  <include location="res.qrc"/>
 </resources>
 <connections/>
</ui>

 widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include<QRadioButton>
#include<QCheckBox>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置单选按钮 男默认选中
    ui->rBtnMan->setCheckable(true);
    //选中女后 打印信息
    connect(ui->rBtnWoman,&QRadioButton::clicked,[=](){
        qDebug()<<"选中了女!";
    });
    //多选按钮
    connect(ui->cBox,&QCheckBox::stateChanged,[=](int state){
        qDebug()<<state;
    });

    //利用listWidget写诗
    QListWidgetItem * item=new QListWidgetItem("锄禾日当午");
    //将第一行放到listWidget控件中
    ui->listWidget->addItem(item);
    //设置居中
    item->setTextAlignment(Qt::AlignHCenter);

    //QStringList
    QStringList list;
    list<<"锄禾日当午"<<"汗滴禾下土"<<"谁知盘中餐"<<"粒粒皆辛苦?";
            ui->listWidget->addItems(list);

    //treeWidget树控件使用

    //设置水平头
    ui->treeWidget->setHeaderLabels(QStringList()<<"英雄"<<"英雄介绍");

    QTreeWidgetItem * liItem=new QTreeWidgetItem(QStringList()<<"力量");
    QTreeWidgetItem * minItem=new QTreeWidgetItem(QStringList()<<"敏捷");
    QTreeWidgetItem * zhiItem=new QTreeWidgetItem(QStringList()<<"智力");
    //追加顶层节点
    ui->treeWidget->addTopLevelItem(liItem);
    ui->treeWidget->addTopLevelItem(minItem);
    ui->treeWidget->addTopLevelItem(zhiItem);

    //追加自己点
    QStringList heroL1;
    heroL1<<"刚被猪"<<"刚被猪刚被猪";
    QTreeWidgetItem *ll=new QTreeWidgetItem(heroL1);
    liItem->addChild(ll);

    //TableWidget控件
    //设置列数
    ui->tableWidget->setColumnCount(3);

    //设置水平表头
    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年龄");

    //设置行数
    ui->tableWidget->setRowCount(5);
    //设置正文
    QStringList nameList;
    nameList<<"亚瑟"<<"赵云"<<"张飞"<<"关羽"<<"花木兰";
    QStringList sexList;
    sexList<<"男"<<"男"<<"男"<<"男"<<"女";

        for(int i=0;i<5;i++){
        int col=0;
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(nameList[i]));
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(sexList.at(i)));
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(QString::number(i+18)));
    }
}

Widget::~Widget()
{
    delete ui;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/695522.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Windows 安装 Redis

安装和配置Redis Redis的安装有两种安装形式&#xff0c;一种是安装包式&#xff0c;另一种是压缩包 注意&#xff1a;windows没有32位的&#xff0c;所以32位机器的朋友考虑换一下机器。 一、安装包式 1、windows环境下的redis需要去github上获取: https://github.com/Mic…

MATLAB matlab图像压缩程序--采用嵌入式小波零树编码算法源码

MATLAB matlab图像压缩程序--采用嵌入式小波零树编码算法源码 function varargout ezw(varargin) % EZW MATLAB code for ezw.fig % EZW, by itself, creates a new EZW or raises the existing % singleton*. % % H EZW returns the handle to a new EZW or…

【裸机开发】GPT 定时器(三) —— 使用GPT实现高精度延时

延时最简单粗暴的方式就是使用空循环来延时&#xff0c;依赖的是时钟主频&#xff08;默认是396M&#xff09;来计数&#xff0c;一旦修改了 6ull 的时钟主频&#xff0c;延时效果就会存在偏差。 因此我们可以使用 EPIT 或者 GPT 的计数功能实现高精度延时&#xff0c;EPIT 是…

电气设备无线测温技术的优势有哪些?安科瑞 许敏

摘 要&#xff1a; 无线测温技术以其安装方便灵活、测温精度高、安全可靠、环境适应性好、便于集中管理等优点&#xff0c; 解决了电气设备长期带电运行状态下的温度在线监测问题&#xff0c; 提高了电气设备的运行可靠性&#xff0c; 在电力行业得到了广泛的应用。本文主要介…

将当前conda环境导出为yaml文件

conda环境的转移和复制 conda导出已有环境&#xff0c;环境会被保存在environment.yaml文件中。 conda env export > environment.yaml 当我们想再次创建该环境&#xff0c;或根据别人提供的.yaml文件复现环境时&#xff0c;就可以通过下面的命令来复现安装环境了。 conda …

【深度学习】Stable Diffusion

Stable Diffusion原理&#xff1a; https://zhuanlan.zhihu.com/p/632866251 训练过程&#xff1a; 文生图方法&#xff1a; 图生图方法&#xff1a;

CSS实现多头像叠加ui效果

第一种实现方式 简单粗暴直接使用margin-right实现&#xff0c;缺点是第一行右侧最右边头像溢出容器&#xff0c;代码中的三行注释的代码放开后可解决这个问题。 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8">&…

SQLyog登录错误解决

sqlyog登录错误号码2058解决 登录本地MySQL数据库 Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\Administrator>mysql -u root -p Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \…

windows10 Linux子系统 Ubuntu 文件互相访问

ubuntu 访问Windows windows的磁盘被挂载到了/mnt下&#xff0c;可以看到我的电脑的c,d,e,f盘&#xff0c; windows 访问 ubuntu 在文件夹输入\wsl$ 再点击Ubuntu-22.04,进入文件夹

CSS 弹性布局

提示&#xff1a;这章比较重要&#xff0c;做复杂页面时经常会用到&#xff01;会不断更新❗ 文章目录 前言主轴和侧轴flex-direction 主轴方向flex-wrap 折行justify-content 主轴排列方式flex-start&#xff1a;默认左对齐flex-end&#xff1a;右对齐center&#xff1a;居中s…

如何在Maven中发布项目到Nexus私有服务器

本篇环境 nexus-3.55.0-01&#xff0c; Nexus安装在本地服务器 http://localhost:8081/maven-3.9.2 发布步骤 在项目机器的Maven的 settings.xml 配置Nexus的账号/密码 在settings.xml 的 <servers>节点增加 <server> 节点&#xff0c; 配置 Nexus 的登陆账号和…

Java使用pdf模板生成pdf文件

文章目录 前言如何生成pdf文件1. 制作pdf模板2. 填充pdf模板生成文件 前言 有时候&#xff0c;业务中我们需要使用pdf模板生成一份pdf文件。如何生成pdf文件&#xff1f; 如下&#xff0c;我们把左侧的模板生成为右侧的填充文件。 如何生成pdf文件 1. 制作pdf模板 &#xff…

【Linux】C++项目实战-UDP服务器

目录 UDP通信函数解析代码举例 广播函数解析代码举例 橙色 UDP通信 函数解析 #include <sys/types.h> #include <sys/socket.h> ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);- 参…

避雷器在线测试仪

一、产品概述 KDYZ-306氧化锌避雷器带电测试仪是用于检测氧化锌避雷器电气性能的专用仪器&#xff0c;该仪器适用于各种电压等级的氧化锌避雷器的带电或停电检测&#xff0c;从而及时发现设备内部绝缘受潮及阀片老化等危险缺陷。 仪器操作简单、使用方便&#xff0c;测量全过…

创建固定大小的文件(window 和 UBUNTU)

1、Windows Windows提供了一个强大的文件系统管理工具&#xff1a;fsutil.exe 例&#xff0c;在D盘上创建一个空文件file.txt&#xff0c;文件大小10k字节 fsutil file createnew D:\file.txt 1000 2、Ubuntu Ubuntu创建一个指定大小的文件用全零填充这个文件&#xff0c;例…

vue3 elementplus table合并

table表格下方合并写法&#xff1a; 1&#xff1a;单行合并 &#xff08;1&#xff09;在标签中加入属性 :summary-method"getSummaries":show-summary"true"<el-table:data"data"id"tableRef"ref"tableRef"row-key"…

CentOS Stream 10 计划已启动,即将进入初始化阶段

导读 但初始化的 CentOS Stream 10 暂时不会对外开放&#xff0c;也不会有太多活跃信息。从 Fedora 周期的规律来看&#xff0c;至少还有六个月的时间&#xff0c;CentOS Stream 10 才会正式启动开发流程&#xff0c;接受来自外部的贡献。周五的公告指出&#xff1a;你会看到 C…

智能优化算法改进策略之局部搜索算子(二)—模式搜索(以正余弦算法和灰狼算法为研究对象)

一、改进点基本介绍&#xff1a; 在目前多数的改进智能优化算法文献中&#xff0c;局部搜索算子的形式多种多样。它们主要被用来增强算法的局部开发能力&#xff0c;进而提升它们在优化问题特别在单峰问题上的收敛性能。作为一种高效的直接搜索法&#xff0c;模式搜索目前已被…

freemarker 使用word模板赋值

1. 引包<dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.28</version></dependency>word文档工具类import freemarker.template.Configuration; import freemarker.template.…

将List转化为String 以逗号隔开

一.前言 在我们日常开发中, 在前后端交互的时候 , 会遇到多个id或其他字段存放到一个字段中, 这时我们会遇到一个List(集合)---->String(单个字段), 这时我们要进行操作数据, 使得我们的数据可以保存到数据库中 . 二.解决方法 2.1 利用StringBurilder或StringBuffer pub…