Detailed explanation of the use of QT QProgressBar control

        This article introduces the various operations of the QProgressBar control in detail, such as: creating a new interface , setting the maximum and minimum values , setting the progress , returning the minimum progress value , returning the maximum progress value , returning the current progress value , resetting the default progress value, and returning the progress bar text , set progress bar text , set display progress bar, set vertical and horizontal, style sheet, signal slot, source code, other articles and other operations.

        QProgressBar (progress bar) is a widget in the Qt framework that is used to visually display the progress of a task or operation. It is usually used in the following situations: 1. Display the progress of the task: The progress bar can display the completion of the task and let the user understand the progress of the task. For example, when a file is being downloaded or copied, a progress bar can be used to display the download or copy progress of the file. 2. Feedback on long-running operations: When performing an operation that takes some time, a progress bar can provide feedback to let the user know that the operation is in progress and show the progress of the operation. This increases the user experience and prevents users from thinking that the application has crashed or become unresponsive. 3. Control the process: The progress bar can also be used as a way to control the process. For example, in a game, a progress bar can be used to represent a character's health or energy bar so that players can understand the character's status. By setting the minimum value, maximum value and current value of the progress bar, you can control the display range and progress of the progress bar. Progress bars can be displayed in a horizontal or vertical orientation, depending on the needs of the application. In summary, QProgressBar is a widget used to visually display the progress of a task or operation, and can provide feedback and control processes to enhance the user experience. .

        There are currently thirty-six articles in this series of QT comprehensive and detailed explanations. This series of articles describes the basic operation and use of QT controls in more detail. Thank you for your attention, likes, and collections.

This article is original by the author. Please attach the source of the article and the link to this article when reprinting.

QT QProgressBar control usage detailed directory

1 Create a new interface

2 Set the maximum and minimum values

3 Set the progress

4 Return to the minimum progress value

5 Return to the maximum progress value

6 Return the current progress value

7 Reset progress defaults

8 Return to progress bar text

9 Set progress bar text

10 Set the display progress bar

11 Set vertical and horizontal

12 style sheets

13 signal slot

14 source code

15 other articles


1 Create a new interface

2 Set the maximum and minimum values

    // 设置进度范围的最小值和最大值
    ui->progressBar->setRange(20,40);

3 Set the progress

    //设置当前进度的值
    ui->progressBar->setValue(50);

4 Return to the minimum progress value

    //返回进度范围的最小值
    miValue = ui->progressBar->minimum();

5 Return to the maximum progress value

    //返回进度范围的最大值
    miValue = ui->progressBar->maximum();

6 Return the current progress value

    //返回当前进度的值
    miValue = ui->progressBar->value();

7 Reset progress defaults

    //重置进度条的值为默认值
    ui->progressBar->reset();

8 Return to progress bar text

    //返回进度条的文本
    ui->progressBar->text();

9 Set progress bar text

    //设置进度条的文本格式
    ui->progressBar->setFormat("CSDN 双子座断点");

10 Set the display progress bar

    //设置是否显示进度条的文本
    ui->progressBar->setTextVisible(true);

11 Set vertical and horizontal

    //设置垂直水平
    ui->progressBar->setOrientation(Qt::Horizontal);//水平        ///Qt::Vertical 垂直

12 style sheets

    // 设置样式表
    ui->progressBar->setStyleSheet("QProgressBar {"
                               "    border: 1px solid gray;"
                               "    border-radius: 5px;"
                               "    background-color: white;"
                               "}"
                               "QProgressBar::chunk {"
                               "    background-color: #2196F3;"
                               "    width: 20px;"
                               "}");
    ui->progressBar->setRange(0, 100);
    ui->progressBar->setValue(50);

13 signal slot

    // 连接信号和槽函数
    connect(ui->progressBar, &QProgressBar::valueChanged, this, &MainWindow::onProgressChanged);
void MainWindow::onProgressChanged(int value) {
    qDebug() << "进度值变为:" << value;
}

14 source code

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
//加入GBK申明,否则中文乱码 全局使用GBK文件操作因为有中文所以使用
#pragma execution_character_set("utf-8")
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void onProgressChanged(int value);
private:
    Ui::MainWindow *ui;

    QString Title;
    QString Version;
    QString BlogText;

};
#endif // MAINWINDOW_H

15 other articles

QT TextEdit control_Gemini Breakpoint's Blog-CSDN Blog_qt textedit

Detailed explanation of the use of QT QComboBox_Gemini Breakpoint's Blog-CSDN Blog

Detailed explanation of QT QtableView operation_Gemini Breakpoint's Blog-CSDN Blog_qtableview addition, deletion, modification and query

Qt QStandardItemModel (1. Super detailed usage)_Gemini Breakpoint's Blog-CSDN Blog_qstandardmodel

Qt QStandardItemModel (2. Super detailed function)_Gemini Breakpoint's Blog-CSDN Blog_qstandarditemmodel click event

Detailed explanation of the use of QT QRadioButton_Gemini Breakpoint's Blog-CSDN Blog_qt radiobutton

Detailed explanation of the use of QT QLineEdit_Gemini Breakpoint's Blog-CSDN Blog_qt qlineedit

Detailed explanation of the use of Qt QMessageBox_Gemini Breakpoint's Blog-CSDN Blog_qt message

QChart line chart, pie chart, bar chart, curve chart_Gemini Breakpoint's Blog-CSDN Blog_qchart Style

Detailed explanation of QChart attributes_Gemini Breakpoint's Blog-CSDN Blog_setanimationoptions

QCharts QValueAxis use_Gemini Breakpoint's Blog-CSDN Blog_qvalueaxis

Qt 5 Waiting Prompt Box (Open Source Dynamic Graphic)_Gemini Breakpoint's Blog-CSDN Blog_qt Waiting Dialog Box

QtDataVisualization Data 3D Visualization_Gemini Breakpoint's Blog-CSDN Blog_qtdatavisualizatio

QT QSpinBox Integer Counter Control Detailed Explanation_Gemini Breakpoint's Blog-CSDN Blog
QT QDoubleSpinBox Floating Point Counter Control (Usage Detailed)_Gemini Breakpoint's Blog-CSDN Blog_qdoublespinbox Signal Slot
QT QSlider, QHorizontalSlider, QVerticalSlider Control Detailed Explanation_Gemini Breakpoint blog-CSDN blog_qslider setting step size

Detailed explanation of the use of QT QTabWidget control_Gemini Breakpoint's Blog-CSDN Blog

Detailed explanation of the use of QT QCalendarWidget control_Gemini Breakpoint's Blog-CSDN Blog

Detailed explanation of the use of QT QStackedWidget control_Gemini Breakpoint's Blog-CSDN Blog

QT QVBoxLayout vertical layout control_Gemini Breakpoint's Blog-CSDN Blog

QT QHBoxLayout horizontal layout control_Gemini breakpoint's blog-CSDN blogQT
QGridLayout grid layout control_Gemini breakpoint's blog-CSDN blog

QT QVerticalSpacer Spring Control_Gemini Breakpoint's Blog-CSDN Blog
QT QHorizontalSpacer Spring Control_Gemini Breakpoint's Blog-CSDN Blog
QT QLine Detailed Usage_Gemini Breakpoint's Blog-CSDN Blog
QT QFontComboBox Detailed Usage_Gemini Breakpoint's Blog- CSDN blog

Detailed explanation of the use of QT QScrollArea control_Gemini Breakpoint's Blog-CSDN Blog

Detailed explanation of the use of QT QToolBox control_Gemini Breakpoint's Blog-CSDN Blog

Detailed explanation of the use of QT QFrame control_Gemini Breakpoint's Blog-CSDN Blog
https://blog.csdn.net/qq_37529913/article/details/132706110

Guess you like

Origin blog.csdn.net/qq_37529913/article/details/132819238