qt-C++笔记之滑动条QSlider和QProgressBar进度条

2024-04-29 00:12

本文主要是介绍qt-C++笔记之滑动条QSlider和QProgressBar进度条,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

qt-C++笔记之滑动条QSlider和QProgressBar进度条

—— 2024-04-28 杭州

本例来自《Qt6 C++开发指南》

文章目录

  • qt-C++笔记之滑动条QSlider和QProgressBar进度条
    • 1.运行
    • 2.阅读笔记
    • 3.文件结构
    • 4.samp4_06.pro
    • 5.main.cpp
    • 6.widget.h
    • 7.widget.cpp
    • 8.widget.ui

1.运行

在这里插入图片描述

2.阅读笔记

在这里插入图片描述

在这里插入图片描述

3.文件结构

在这里插入图片描述

4.samp4_06.pro

QT       += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \widget.cppHEADERS += \widget.hFORMS += \widget.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

5.main.cpp

#include "widget.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();return a.exec();
}

6.widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private slots://自定义槽函数void do_valueChanged(int value);void on_chkBox_Visible_clicked(bool checked);void on_chkBox_Inverted_clicked(bool checked);void on_radio_Percent_clicked();void on_radio_Value_clicked();private:Ui::Widget *ui;
};#endif // WIDGET_H

7.widget.cpp

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);//将表盘,滑动条,卷滚条的valueChanged()信号与自定义槽函数关联connect(ui->slider,SIGNAL(valueChanged(int)),this, SLOT(do_valueChanged(int)));connect(ui->scrollBar,SIGNAL(valueChanged(int)),this, SLOT(do_valueChanged(int)));connect(ui->dial,SIGNAL(valueChanged(int)),this, SLOT(do_valueChanged(int)));}Widget::~Widget()
{delete ui;
}void Widget::do_valueChanged(int value)
{//自定义槽函数ui->progressBar->setValue(value);
}void Widget::on_chkBox_Visible_clicked(bool checked)
{//textVisibleui->progressBar->setTextVisible(checked);
}void Widget::on_chkBox_Inverted_clicked(bool checked)
{//InvertedAppearanceui->progressBar->setInvertedAppearance(checked);
}void Widget::on_radio_Percent_clicked()
{//显示格式--百分比ui->progressBar->setFormat("%p%");
}void Widget::on_radio_Value_clicked()
{//显示格式--当前值ui->progressBar->setFormat("%v");
}

8.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>436</width><height>299</height></rect></property><property name="font"><font><pointsize>10</pointsize></font></property><property name="windowTitle"><string>Slider和ProgreeeBar</string></property><layout class="QVBoxLayout" name="verticalLayout_2"><item><widget class="QGroupBox" name="groupBox"><property name="title"><string>滑动输入</string></property><layout class="QHBoxLayout" name="horizontalLayout_2"><item><widget class="QDial" name="dial"><property name="maximum"><number>200</number></property><property name="value"><number>20</number></property><property name="orientation"><enum>Qt::Horizontal</enum></property><property name="wrapping"><bool>false</bool></property><property name="notchTarget"><double>5.000000000000000</double></property><property name="notchesVisible"><bool>true</bool></property></widget></item><item><layout class="QGridLayout" name="gridLayout_2"><item row="0" column="0"><widget class="QLabel" name="label"><property name="text"><string>滑动条</string></property></widget></item><item row="0" column="1"><widget class="QSlider" name="slider"><property name="maximum"><number>200</number></property><property name="value"><number>23</number></property><property name="orientation"><enum>Qt::Horizontal</enum></property><property name="tickPosition"><enum>QSlider::TicksAbove</enum></property></widget></item><item row="1" column="0"><widget class="QLabel" name="label_2"><property name="text"><string>卷滚条</string></property></widget></item><item row="1" column="1"><widget class="QScrollBar" name="scrollBar"><property name="maximum"><number>200</number></property><property name="value"><number>23</number></property><property name="orientation"><enum>Qt::Horizontal</enum></property></widget></item></layout></item></layout></widget></item><item><widget class="QGroupBox" name="groupBox_2"><property name="title"><string>ProgressBar显示和设置</string></property><layout class="QVBoxLayout" name="verticalLayout"><item><widget class="QFrame" name="frame"><layout class="QHBoxLayout" name="horizontalLayout"><property name="leftMargin"><number>2</number></property><property name="topMargin"><number>2</number></property><property name="rightMargin"><number>2</number></property><property name="bottomMargin"><number>0</number></property><item><widget class="QLabel" name="label_3"><property name="text"><string>进度条</string></property></widget></item><item><widget class="QProgressBar" name="progressBar"><property name="maximum"><number>200</number></property><property name="value"><number>24</number></property></widget></item></layout></widget></item><item><widget class="QFrame" name="frame_2"><property name="frameShadow"><enum>QFrame::Raised</enum></property><layout class="QGridLayout" name="gridLayout"><item row="1" column="1"><widget class="QRadioButton" name="radio_Value"><property name="text"><string>显示格式--当前值</string></property><property name="checked"><bool>false</bool></property></widget></item><item row="1" column="0"><widget class="QRadioButton" name="radio_Percent"><property name="text"><string>显示格式--百分比</string></property><property name="checked"><bool>true</bool></property></widget></item><item row="0" column="1"><widget class="QCheckBox" name="chkBox_Inverted"><property name="text"><string>invertedAppearance</string></property></widget></item><item row="0" column="0"><widget class="QCheckBox" name="chkBox_Visible"><property name="text"><string>textVisible</string></property><property name="checked"><bool>true</bool></property></widget></item></layout></widget></item></layout></widget></item></layout></widget><layoutdefault spacing="6" margin="11"/><resources/><connections/>
</ui>

这篇关于qt-C++笔记之滑动条QSlider和QProgressBar进度条的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/944632

相关文章

C++一个数组赋值给另一个数组方式

《C++一个数组赋值给另一个数组方式》文章介绍了三种在C++中将一个数组赋值给另一个数组的方法:使用循环逐个元素赋值、使用标准库函数std::copy或std::memcpy以及使用标准库容器,每种方... 目录C++一个数组赋值给另一个数组循环遍历赋值使用标准库中的函数 std::copy 或 std::

Qt 中集成mqtt协议的使用方法

《Qt中集成mqtt协议的使用方法》文章介绍了如何在工程中引入qmqtt库,并通过声明一个单例类来暴露订阅到的主题数据,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一,引入qmqtt 库二,使用一,引入qmqtt 库我是将整个头文件/源文件都添加到了工程中进行编译,这样 跨平台

C++使用栈实现括号匹配的代码详解

《C++使用栈实现括号匹配的代码详解》在编程中,括号匹配是一个常见问题,尤其是在处理数学表达式、编译器解析等任务时,栈是一种非常适合处理此类问题的数据结构,能够精确地管理括号的匹配问题,本文将通过C+... 目录引言问题描述代码讲解代码解析栈的状态表示测试总结引言在编程中,括号匹配是一个常见问题,尤其是在

使用C++实现链表元素的反转

《使用C++实现链表元素的反转》反转链表是链表操作中一个经典的问题,也是面试中常见的考题,本文将从思路到实现一步步地讲解如何实现链表的反转,帮助初学者理解这一操作,我们将使用C++代码演示具体实现,同... 目录问题定义思路分析代码实现带头节点的链表代码讲解其他实现方式时间和空间复杂度分析总结问题定义给定

C++初始化数组的几种常见方法(简单易懂)

《C++初始化数组的几种常见方法(简单易懂)》本文介绍了C++中数组的初始化方法,包括一维数组和二维数组的初始化,以及用new动态初始化数组,在C++11及以上版本中,还提供了使用std::array... 目录1、初始化一维数组1.1、使用列表初始化(推荐方式)1.2、初始化部分列表1.3、使用std::

C++ Primer 多维数组的使用

《C++Primer多维数组的使用》本文主要介绍了多维数组在C++语言中的定义、初始化、下标引用以及使用范围for语句处理多维数组的方法,具有一定的参考价值,感兴趣的可以了解一下... 目录多维数组多维数组的初始化多维数组的下标引用使用范围for语句处理多维数组指针和多维数组多维数组严格来说,C++语言没

c++中std::placeholders的使用方法

《c++中std::placeholders的使用方法》std::placeholders是C++标准库中的一个工具,用于在函数对象绑定时创建占位符,本文就来详细的介绍一下,具有一定的参考价值,感兴... 目录1. 基本概念2. 使用场景3. 示例示例 1:部分参数绑定示例 2:参数重排序4. 注意事项5.

使用C++将处理后的信号保存为PNG和TIFF格式

《使用C++将处理后的信号保存为PNG和TIFF格式》在信号处理领域,我们常常需要将处理结果以图像的形式保存下来,方便后续分析和展示,C++提供了多种库来处理图像数据,本文将介绍如何使用stb_ima... 目录1. PNG格式保存使用stb_imagephp_write库1.1 安装和包含库1.2 代码解

C++实现封装的顺序表的操作与实践

《C++实现封装的顺序表的操作与实践》在程序设计中,顺序表是一种常见的线性数据结构,通常用于存储具有固定顺序的元素,与链表不同,顺序表中的元素是连续存储的,因此访问速度较快,但插入和删除操作的效率可能... 目录一、顺序表的基本概念二、顺序表类的设计1. 顺序表类的成员变量2. 构造函数和析构函数三、顺序表

使用C++实现单链表的操作与实践

《使用C++实现单链表的操作与实践》在程序设计中,链表是一种常见的数据结构,特别是在动态数据管理、频繁插入和删除元素的场景中,链表相比于数组,具有更高的灵活性和高效性,尤其是在需要频繁修改数据结构的应... 目录一、单链表的基本概念二、单链表类的设计1. 节点的定义2. 链表的类定义三、单链表的操作实现四、