QT——tableWidget-跳变之舞V1.0-记录学习【1】

QT——tableWidget-跳变之舞V1.0-记录学习【1】


文章目录

  • QT——tableWidget-跳变之舞V1.0-记录学习【1】
  • 前言
  • 一、利用QT创建项目文件
    • 1.1 完整项目文件如下图所示:
    • 1.2 演示:
  • 二、声明文件:
    • 2.1 主界面声明文件:mainwindow.h;
    • 2.2 控制窗口声明文件:form.h;
    • 2.3 线程声明文件:mythread.h;
  • 三、源文件:业务逻辑实现
    • 3.1 主界面逻辑文件:mainwindow.cpp;
    • 3.2 控制窗口逻辑文件:form.cpp;
    • 3.3 线程逻辑文件:mythread.cpp;
    • 3.4 主界面监控及显示:main.cpp;
  • 四、UI设计文件:
    • 4.1 控制窗口UI文件form.ui;
    • 4.2 主界面UI文件mainwindow.ui;
  • 五、qrc资源文件:
  • 六、个人初步理解QT信号与槽函数的建立及通讯;
    • 演示:


前言

学习QT-tableWidge的部分使用方法,自制跳变表格娱乐小工具 V1.0(* ̄︶ ̄)


一、利用QT创建项目文件

备注:此处不讲解如何新建项目,创建项目。

1.1 完整项目文件如下图所示:

在这里插入图片描述

  1. Headers文件夹下的文件为头文件,主要是声明定义文件;
  2. Sources文件夹下的文件为源文件,主要是功能实现文件;
  3. Forms文件夹下的文件为ui文件,主要是UI设计文件;
  4. Resources文件夹下的文件为qrc文件,主要是放入资源文件;
  5. Other files文件夹下的文件为其他文件;

1.2 演示:

在这里插入图片描述


二、声明文件:

包括:主界面声明文件:mainwindow.h,控制窗口声明文件:form.h,线程声明文件:mythread.h;

2.1 主界面声明文件:mainwindow.h;

//这段代码的作用是防止头文件的重复包含,确保在编译过程中每个源文件只包含一次该头文件。
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <form.h>
#include <mythread.h>

//QT_BEGIN_NAMESPACE是Qt框架中的一个宏定义,用于定义一个命名间。
QT_BEGIN_NAMESPACE
//C++中,命名空间使用namespace来声明,并使用{ }来界定命名空间的作用域
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

//类
class MainWindow :
    public QMainWindow //关键字 public 确定了类成员的访问属性。在类对象作用域内,公共成员在类的外部是可访问的。
{
    Q_OBJECT //Q_OBJECT是Qt框架中用于支持信号与槽机制、动态属性和反射等特性的宏定义。

    public:
        //带有一个参数的构造函数,参数类型为QWidget指针,参数名为parent。构造函数使用了默认参数值nullptr,表示如果没有传递参数,则parent将被设置为nullptr。
        MainWindow(QWidget *parent = nullptr);
        //这是一个默认析构函数,没有任何参数。析构函数在对象被销毁时自动调用,用于释放对象所占用的资源。
        ~MainWindow();
        //覆写closeEvent函数
         void closeEvent(QCloseEvent *);

    // private slots是Qt框架中的一种特殊声明,用于定义私有的槽函数。槽函数是用于响应信号的函数,而私有的槽函数只能在类内部被调用。
    private slots:
        void onMenuButtonClicked();
        void getStr(QString &,QString &,QString &);

    private:
        //Ui::MainWindow是一个类,通常用于设计和管理主窗口的用户界面。
        //一个指向MainWindow类的对象的指针
        Ui::MainWindow *ui;
    private:
         Form *configWindow = new Form;
         void onshuju();
    private:
        void settable();
        void addrowcolum(QString &,QString &,QString &);
        
    private:
        void returnNumber();
        void tiaobian();
        void threadqidong(int value);
        MyThread *thread = new MyThread;
		
		//创建信号
    signals:
        void mainWidgetStr(QString &,QString &);
	  //创建槽函数
    private slots:
        void tiaobiansloat(int value);

};
#endif // MAINWINDOW_H

2.2 控制窗口声明文件:form.h;

#ifndef FORM_H
#define FORM_H

#include <QWidget>

namespace Ui {
class Form;
}

class Form : public QWidget
{
    Q_OBJECT

public:
    explicit Form(QWidget *parent = nullptr);
    ~Form();

private slots:
    void on_pushButton_clicked();

    void mainWidgetStr(QString &str,QString &strs);

    void on_pushButton_3_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::Form *si;


private:
    void show_ui();

signals:
    void setStr(QString &str,QString &strs,QString &);
};

#endif // FORM_H

2.3 线程声明文件:mythread.h;

#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>

class MyThread : public QThread
{
    Q_OBJECT

public:
    explicit MyThread(QObject *parent = 0);
    void stop();
    void sleeptimeset(int);

protected:
    void run();

private:
    volatile bool stopped;

signals:
    void sendinfo(int);
};

#endif // MYTHREAD_H


三、源文件:业务逻辑实现

包括:主界面逻辑文件:mainwindow.cpp,控制窗口逻辑文件:form.cpp,线程逻辑文件:mythread.cpp,主界面监控:main.cpp;

3.1 主界面逻辑文件:mainwindow.cpp;

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>  //C++ 语言定义了一些头文件,这些头文件包含了程序中必需的或有用的信息
#include "form.h"
#include "qmessagebox.h"
#include "qevent.h"
#include "QTableWidget"
#include <QTableWidgetItem>
#include <QIcon>
#include <QDir>
#include <QDebug>
#include <QRandomGenerator>


//using namespace std; 告诉编译器使用 std 命名空间。命名空间是 C++ 中一个相对新的概念
using namespace std;

int ret = 1;
int randomNumber0 = 0;
int randomNumber1 = 0;
int randomNumber2 = 0;
int numbers =0;
char a[12] = { 0 }; //是一个长度为12的字符数组,并且数组中每个元素都被初始化为0。
double decimalNum = 0.1;


MainWindow::MainWindow(QWidget *parent):
     QMainWindow(parent),
     ui(new Ui::MainWindow)
   //MainWindow::MainWindow(QWidget *parent)构造函数的作用是创建MainWindow类的对象,并初始化其UI界面

{
    ui->setupUi(this);  //初始化UI
    // 连接信号和槽
    //ui->tool是一个指向用户界面中的工具按钮的指针。&QAction::triggered是一个信号,表示当工具按钮被触发时发出的信号。
    //this是指向当前窗口对象的指针,而MainWindow::onMenuButtonClicked是一个槽函数,表示当工具按钮被触发时要执行的函数。
    connect(ui->tool, &QAction::triggered, this, &MainWindow::onMenuButtonClicked);

    /*configWindow为发出信号的对象,SIGNAL(setStr(QString&))为信号,this为接收信号的对象,SLOT(getStr(QString&))为槽函数。
     * 意思是当configWindow对象发送setStr信号时,this对象的getStr槽函数将被调用,并且会传递一个QString类型的参数。
     * 这种机制使得对象间的通信更加灵活方便。*/
    connect(configWindow,SIGNAL(setStr(QString&,QString &,QString &)), this, SLOT(getStr(QString&,QString &,QString &)));

    //连接信号和槽函数
    connect(thread,SIGNAL(sendinfo(int)), this, SLOT(tiaobiansloat(int)));
    // 设置窗口标题
    this->setWindowTitle("QT5.1 ");
    this->setWindowIcon((QIcon(":/build-00000-Desktop_Qt_5_14_2_MinGW_64_bit-Release/main.jpg")));
    settable();
    //获取坐标
    // 获取窗口四个角的坐标
    QRect rect = this->geometry();  // 获取窗口位置和大小
    int x1 = rect.x();              // 左上角x坐标
    int y1 = rect.y();              // 左上角y坐标
    int x2 = x1 + rect.width();     // 右上角x坐标
    int y2 = y1;                    // 右上角y坐标
//    int x3 = x2;                    // 右下角x坐标
//    int y3 = y1 + rect.height();    // 右下角y坐标
//    int x4 = x1;                    // 左下角x坐标
//    int y4 = y3;                    // 左下角y坐标

    qDebug() <<"右上角x,y坐标:"<<x2 <<y2 ;
    this->move(500,250);     //窗口打开位置设置
}


void MainWindow::onshuju()
{
    if (ret == 0)
    {
        configWindow->show();
        cout<<  "open new window" << endl;
    }
    else
    {
        configWindow->close();
        cout<<  "close new window" << endl;
    }

}



void MainWindow::getStr(QString &str,QString &strs,QString &text)
{
    qDebug() << "主界面接收数据:"<< str << strs <<text;
    addrowcolum(str,strs,text);
    //发送信号到控制窗口
    //emit mainWidgetStr(str,strs);

    //将字符串转为浮点数
    decimalNum = str.toDouble();

    //跳变业务逻辑启动控制
    if(strs == "start_putton")
    {
        qDebug() << "启动按钮....";
        threadqidong(1);
    }else if (strs == "stop_putton")
    {
        qDebug() << "停止按钮....";
        threadqidong(2);
    }

}


void MainWindow::addrowcolum(QString &str1,QString &str2,QString &text)
{
    int shuju = str2.toInt();
    if (text== "增加" and str1 == "列设置")
    {
        for(int shuzhi=0;shuzhi<shuju;shuzhi++){

            int number = ui->tableWidget->columnCount();
            ui->tableWidget->insertColumn(number);
        }
    }else if ((text== "增加" and str1 == "行设置"))
    {
        for(int shuzhi=0;shuzhi<shuju;shuzhi++){

            int number = ui->tableWidget->rowCount();
            ui->tableWidget->insertRow(number);
        }

    }else if ((text== "删除" and str1 == "行设置"))
    {
        for(int shuzhi=0;shuzhi<shuju;shuzhi++){
            int number = ui->tableWidget->rowCount();
            ui->tableWidget->removeRow(number-1);
        }

    }else if ((text== "删除" and str1 == "列设置"))
    {
        for(int shuzhi=0;shuzhi<shuju;shuzhi++){
            int number = ui->tableWidget->columnCount();
            ui->tableWidget->removeColumn(number-1);
        }
    }
}


void MainWindow::tiaobiansloat(int value)
{
   // qDebug()<< "设置睡眠时间:" <<decimalNum;
   // 设置睡眠时间
    thread->sleeptimeset(decimalNum*1000);
    tiaobian();

}

void MainWindow::threadqidong(int value)
{

    if (value == 1){
        qDebug() << "启动线程...";
        //启用线程
        thread->start();
    }
    else if(value == 2)
    {
        qDebug() << "停止线程...";
        thread->stop();
    }
}


void MainWindow::tiaobian()
{
    QTableWidgetItem *item;

    for(int row = 0; row < ui->tableWidget->rowCount(); row++){
        for(int column = 0; column < ui->tableWidget->columnCount(); column++){
            item = new QTableWidgetItem();
            item->setTextAlignment(Qt::AlignCenter); //居中
            returnNumber();
            item->setBackground(QColor(randomNumber0, randomNumber1, randomNumber2));  //设置颜色

            //设置单元格内容
            item->setText(a);
            //qDebug() << "Number: " << a;

            ui->tableWidget->setItem(row, column, item);

            }
        }
}

void MainWindow::onMenuButtonClicked()
{
    ret = 0;
    cout << "===start Sucess=====" << endl;
    connect(this,SIGNAL(mainWidgetStr(QString&,QString &)), configWindow, SLOT(mainWidgetStr(QString&,QString &)));
    onshuju();
    ret = 1;
}



void MainWindow::closeEvent(QCloseEvent *event)
{
    // 在这里编写关闭窗口时的处理逻辑
    QMessageBox::StandardButton button = QMessageBox::question(this, "确认关闭", "确定要关闭窗口吗?", QMessageBox::Yes | QMessageBox::No);
    if (button == QMessageBox::Yes)
    {
        onshuju();
        // 用户确认关闭窗口,调用父类的closeEvent()函数关闭窗口
        event->accept();
    }
    else {
        // 用户取消关闭窗口,忽略该事件
        event->ignore();
    }
}



void MainWindow::settable()
{
    //设置表格表头的样式
    ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background:lightblue;}");
    ui->tableWidget->resizeColumnsToContents();//自动调整表格控件的列宽,使得表格中的内容能够全部显示出来。
    ui->tableWidget->resizeRowsToContents();  //用于自动调整表格控件的行高,使得表格中的内容能够全部显示出来
    ui->tableWidget->horizontalHeader()->setStretchLastSection(true);//Qt中设置表格控件中表头自适应宽度的方法之一。
    //水平表头栏的单元格大小模式为拉伸模式,即根据控件的大小自动调整每一列的宽度,使得每一列的宽度都相等。这种设置可以使得表格数据更加美观和易于查看。
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    //ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); //将第一列的宽度调整为其内容的宽度。

    ui->tableWidget->setWordWrap(true);//设置表格控件的自适应行高属性为true

    //设置所有内容居中
    QTableWidgetItem *item; //指向QTableWidgetItem对象的指针
    for(int row = 0; row < ui->tableWidget->rowCount(); row++){
        for(int column = 0; column < ui->tableWidget->columnCount(); column++){
            item = new QTableWidgetItem();

            item->setTextAlignment(Qt::AlignCenter); //居中

            returnNumber();
            item->setBackground(QColor(randomNumber0, randomNumber1, randomNumber2));  //设置颜色

            //设置单元格内容
            item->setText(a);
            //qDebug() << "Number: " << a;

            ui->tableWidget->setItem(row, column, item);

            }
        }
    // 禁止编辑单元格
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

    QString path = QDir::currentPath();//打印工作路径
    qDebug() << path;

    //获取表格长度和宽度
    int width1 = ui->tableWidget->width();
    int height1 = ui->tableWidget->height();

    cout<<"width:" << width1 <<endl;
    cout<<"height:" << height1 <<endl;

    ui->tableWidget->verticalHeader()->setDefaultSectionSize(30); //设置所有行的高度
    cout<<"table edit over!" << endl;
}


void MainWindow::returnNumber()
{
    // 生成一个介于0到256之间的随机数
    randomNumber0 = QRandomGenerator::global()->bounded(256);
    randomNumber1 = QRandomGenerator::global()->bounded(256);
    randomNumber2 = QRandomGenerator::global()->bounded(256);

    //    qDebug() << "Random Number: " << randomNumber1;
    //    qDebug() << "Random Number: " << randomNumber2;
     numbers = QRandomGenerator::global()->bounded(11);
     //将整数类型的变量numbers格式化成字符串类型,然后将格式化后的字符串存储到字符数组a中。
     //其中,第二个参数12表示字符数组a的大小,第三个参数"%d"表示将整数按十进制格式输出到字符串中。
     //如果格式化后的字符串长度超过了11个字符(包括’\0’),则会在字符数组a的末尾加上’\0’截断字符串,确保不会发生溢出。
     snprintf(a,12,"%d",numbers);

}

MainWindow::~MainWindow()
{
    //delete ui; 是一个用于释放动态分配的内存的操作。在C++中,
    //当我们使用new关键字创建一个对象时,需要使用delete关键字来释放这个对象所占用的内存空间,以防止内存泄漏。
    cout << "relase neicun" << endl;
    delete ui;

}

3.2 控制窗口逻辑文件:form.cpp;

#include "form.h"
#include "ui_form.h"
#include <iostream>  //C++ 语言定义了一些头文件,这些头文件包含了程序中必需的或有用的信息
#include <QDebug>

using namespace std;

/*控制窗口 */

Form::Form(QWidget *parent) :
    QWidget(parent),
    si(new Ui::Form)
{
    si->setupUi(this);
    this->setWindowIcon((QIcon(":/build-00000-Desktop_Qt_5_14_2_MinGW_64_bit-Release/form.jpg")));
    this->move(1268,250);     //窗口打开位置设置
    this->setWindowTitle("控制窗口 ");
}

Form::~Form()
{
    cout<<"close Form" << endl;
    delete si;
}

void Form::on_pushButton_clicked()

{
    QString text = si->pushButton->text();
    //获取设置项
    QString sets = si->comboBox_2->currentText();

    //获取行数据
    QString a = si->comboBox->currentText();

    //发送信号到主界面
    emit setStr(sets,a,text);

}


void Form::mainWidgetStr(QString &str,QString &strs)
{
    qDebug() << "控制窗口接收数据:" << strs << str;
}


void Form::show_ui()
{
    this->show();

}

//启动跳变
void Form::on_pushButton_3_clicked()
{
    QString text = si->pushButton_3->text();
    if (text == "启动"){
        QString sets = "start_putton";
        //获取跳变速度
        QString a = si->comboBox_3->currentText();
        //发送信号到主界面
        emit setStr(a,sets,text);
        si->pushButton_3->setText("停止");
        si->pushButton->setDisabled(true);
        si->pushButton_2->setDisabled(true);
    }
    else if (text == "停止") {
        QString sets = "stop_putton";
        //获取跳变速度
        QString a = si->comboBox_3->currentText();
        //发送信号到主界面
        emit setStr(a,sets,text);
        si->pushButton_3->setText("启动");
        si->pushButton->setDisabled(false);
        si->pushButton_2->setDisabled(false);
    }

}

void Form::on_pushButton_2_clicked()
{
     QString text = si->pushButton_2->text();
    //获取设置项
    QString sets = si->comboBox_2->currentText();

    //获取行数据
    QString a = si->comboBox->currentText();

    //发送信号到主界面
    emit setStr(sets,a,text);
}

3.3 线程逻辑文件:mythread.cpp;

#include "mythread.h"

int timeset = 200;

MyThread::MyThread(QObject *parent) :
    QThread(parent)
{
    stopped = false;
}

void MyThread::run()
{
    stopped = false;
    int shuju = 1;
    while (!stopped) {
        QThread::msleep(timeset);  // 休眠时间设置;
        emit sendinfo(shuju);
    }
}

void MyThread::stop()
{
    stopped = true;
}

void MyThread::sleeptimeset(int value=200)
{
    timeset = value;
}

3.4 主界面监控及显示:main.cpp;

#include "mainwindow.h"
#include "form.h"
#include <QApplication>

/* QApplication应用程序类

                管理图形用户界面应用程序的控制流和主要设置。

                是Qt生命,一个程序要确保一直运行,就肯定至少得有一个循环,这就是Qt主消息循环,在其中完成来自窗口系统和其它资源的所有事件消息处理和调度。它也处理应用程序的初始化和结束,并且提供对话管理。

                对于任何一个使用Qt的图形用户界面应用程序,都正好存在一个QApplication 对象,不论这个应用程序在同一时刻有多少个窗口。

*/

//主界面监控

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;       //继承UI
    w.show();           //显示界面
    // 程序进入消息循环,等待对用户输入进行响应。这里main()把控制权转交给Qt,Qt完成事件处理工作,当应用程序退出的时候exec()的值就会返回。在exec()中,Qt接受并处理用户和系统的事件并且把它们传递给适当的窗口部件。
    return a.exec();
}


四、UI设计文件:

包括:主界面UI文件mainwindow.ui;控制窗口UI文件form.ui

4.1 控制窗口UI文件form.ui;

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>392</width>
    <height>214</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout">
   <item>
    <widget class="QGroupBox" name="groupBox">
     <property name="title">
      <string>控制窗口</string>
     </property>
     <layout class="QGridLayout" name="gridLayout_2">
      <item row="0" column="4">
       <widget class="QPushButton" name="pushButton">
        <property name="minimumSize">
         <size>
          <width>0</width>
          <height>25</height>
         </size>
        </property>
        <property name="styleSheet">
         <string notr="true">QPushButton:hover
{
background-color: rgb(30, 144, 255);
}
QPushButton:pressed
{
background-color: #FFFF00; /*伪状态经过时背景色*/ 
border-style: inset;
}
QPushButton:!enabled{
background-color: rgb(100, 100, 100);
border-style: inset;
}
</string>
        </property>
        <property name="text">
         <string>增加</string>
        </property>
       </widget>
      </item>
      <item row="0" column="5">
       <widget class="QPushButton" name="pushButton_2">
        <property name="minimumSize">
         <size>
          <width>0</width>
          <height>25</height>
         </size>
        </property>
        <property name="styleSheet">
         <string notr="true">QPushButton:hover
{
background-color: rgb(30, 144, 255);
}
QPushButton:pressed
{
background-color: #FFFF00; /*伪状态经过时背景色*/ 
border-style: inset;
}
QPushButton:!enabled{
background-color: rgb(100, 100, 100);
border-style: inset;
}
</string>
        </property>
        <property name="text">
         <string>删除</string>
        </property>
       </widget>
      </item>
      <item row="0" column="1">
       <widget class="QComboBox" name="comboBox_2">
        <property name="minimumSize">
         <size>
          <width>0</width>
          <height>25</height>
         </size>
        </property>
        <property name="styleSheet">
         <string notr="true">background-color: #F5F5F5;
QComboBox QAbstractItemView::item{
height:36px;
color:#666666;
padding-left:9px;
background-color:#FFFFFF;
}
QComboBox QAbstractItemView::item:hover{ //悬浮
background-color:#409CE1;
color:#ffffff;
}
QComboBox QAbstractItemView::item:selected{//选中
background-color:#409CE1;
color:#ffffff;
}</string>
        </property>
        <item>
         <property name="text">
          <string>列设置</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>行设置</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="0" column="3">
       <widget class="QComboBox" name="comboBox">
        <property name="minimumSize">
         <size>
          <width>0</width>
          <height>25</height>
         </size>
        </property>
        <property name="styleSheet">
         <string notr="true">background-color: #F5F5F5;
QComboBox QAbstractItemView::item{
height:36px;
color:#666666;
padding-left:9px;
background-color:#FFFFFF;
}
QComboBox QAbstractItemView::item:hover{ //悬浮
background-color:#409CE1;
color:#ffffff;
}
QComboBox QAbstractItemView::item:selected{//选中
background-color:#409CE1;
color:#ffffff;
}</string>
        </property>
        <item>
         <property name="text">
          <string>1</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>2</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>3</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="1" column="1">
       <widget class="QLabel" name="label">
        <property name="minimumSize">
         <size>
          <width>0</width>
          <height>25</height>
         </size>
        </property>
        <property name="frameShape">
         <enum>QFrame::Panel</enum>
        </property>
        <property name="frameShadow">
         <enum>QFrame::Raised</enum>
        </property>
        <property name="text">
         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;跳变速度:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
        </property>
       </widget>
      </item>
      <item row="1" column="4">
       <widget class="QPushButton" name="pushButton_3">
        <property name="minimumSize">
         <size>
          <width>0</width>
          <height>25</height>
         </size>
        </property>
        <property name="styleSheet">
         <string notr="true">QPushButton:hover
{
background-color: rgb(30, 144, 255);
}
QPushButton:pressed
{
background-color: #FFFF00; /*伪状态经过时背景色*/ 
border-style: inset;
}
QPushButton:!enabled{
background-color: rgb(100, 100, 100);
border-style: inset;
}
</string>
        </property>
        <property name="text">
         <string>启动</string>
        </property>
       </widget>
      </item>
      <item row="1" column="3">
       <widget class="QComboBox" name="comboBox_3">
        <property name="minimumSize">
         <size>
          <width>0</width>
          <height>25</height>
         </size>
        </property>
        <property name="styleSheet">
         <string notr="true">background-color: #F5F5F5;
QComboBox QAbstractItemView::item{
height:36px;
color:#666666;
padding-left:9px;
background-color:#FFFFFF;
}
QComboBox QAbstractItemView::item:hover{ //悬浮
background-color:#409CE1;
color:#ffffff;
}
QComboBox QAbstractItemView::item:selected{//选中
background-color:#409CE1;
color:#ffffff;
}</string>
        </property>
        <item>
         <property name="text">
          <string>0.2</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>0.5</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>1</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>2</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>3</string>
         </property>
        </item>
       </widget>
      </item>
     </layout>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

4.2 主界面UI文件mainwindow.ui;

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>768</width>
    <height>468</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
     <widget class="QTableWidget" name="tableWidget">
      <row>
       <property name="text">
        <string>0</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>1</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>3</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>4</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>5</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>6</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>7</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>8</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>9</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>10</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>11</string>
       </property>
      </row>
      <row>
       <property name="text">
        <string>12</string>
       </property>
      </row>
      <column>
       <property name="text">
        <string>1</string>
       </property>
      </column>
      <column>
       <property name="text">
        <string>2</string>
       </property>
      </column>
      <column>
       <property name="text">
        <string>3</string>
       </property>
      </column>
      <column>
       <property name="text">
        <string>4</string>
       </property>
      </column>
      <column>
       <property name="text">
        <string>5</string>
       </property>
      </column>
      <column>
       <property name="text">
        <string>6</string>
       </property>
      </column>
      <column>
       <property name="text">
        <string>7</string>
       </property>
      </column>
      <item row="0" column="0">
       <property name="text">
        <string/>
       </property>
       <property name="toolTip">
        <string extracomment="123"/>
       </property>
      </item>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>768</width>
     <height>23</height>
    </rect>
   </property>
   <widget class="QMenu" name="menu">
    <property name="title">
     <string>控制工具</string>
    </property>
    <addaction name="tool"/>
   </widget>
   <addaction name="menu"/>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
  <action name="tool">
   <property name="text">
    <string>Start_tool</string>
   </property>
  </action>
 </widget>
 <resources/>
 <connections/>
</ui>


五、qrc资源文件:

注明:qrc文件基本就是添加图片之类的资源文件,设置界面图标,背景图片之类的,此处不多赘述!

六、个人初步理解QT信号与槽函数的建立及通讯;

演示:

在这里插入图片描述

前提:可以建立信号和槽函数
1、在1号头文件中,先声明一个信号,在对应1号源文件中创建一个emit信号;
在这里插入图片描述

2、在2号头文件中,new一个指向1号源文件中类的指针,并创建连接信号与槽函数的关系;
3、槽函数在2号头文件中先声明,然后再在源文件中创建一个槽函数。在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Python框架Django入门教程

Django 是一个使用 Python 编程语言开发的、免费且开源的 Web 应用框架。它遵循 "DRY&#xff08;Dont Repeat Yourself&#xff09;" 原则&#xff0c;旨在简化创建功能丰富的、高效率的 Web 网站。Django 提供了模型-视图-控制器&#xff08;MVC&#xff09;架构的…

C++ VScode: launch: program ...... dose not exist

VScode: launch: program … dose not exist 介绍 参考VS Code 配置 C/C 编程运行环境&#xff08;保姆级教程&#xff09;教程配置了VSCode。在配置launch.json适用多个.c 文件编译时&#xff0c;弹出下面错误。 原因和解决方法 是task.json 默认配置的问题。 默认的 cwd参…

Git详解之五:分布式Git

为了便于项目中的所有开发者分享代码&#xff0c;我们准备好了一台服务器存放远程 Git 仓库。经过前面几章的学习&#xff0c;我们已经学会了一些基本的本地工作流程中所需用到的命令。接下来&#xff0c;我们要学习下如何利用 Git 来组织和完成分布式工作流程。 特别是&#…

回归预测 | Matlab实现SMA-GPR黏菌算法优化高斯过程回归多变量回归预测

回归预测 | Matlab实现SMA-GPR黏菌算法优化高斯过程回归多变量回归预测 目录 回归预测 | Matlab实现SMA-GPR黏菌算法优化高斯过程回归多变量回归预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 Matlab实现SMA-GPR黏菌算法优化高斯过程回归多变量回归预测 1.Matlab实现…

轻松玩转Python文件操作:移动、删除

哈喽&#xff0c;大家好&#xff0c;我是木头左&#xff01; Python文件操作基础 在处理计算机文件时&#xff0c;经常需要执行如移动和删除等基本操作。Python提供了一些内置的库来帮助完成这些任务&#xff0c;其中最常用的就是os模块和shutil模块。这两个模块包含了许多与文…

李彦宏回顾大模型重构百度这一年

“大模型我们走在最前面&#xff0c;我们需要去勇闯无人区&#xff0c;需要去冒前人没有冒过的风险。”近日&#xff0c;在百度一场内部颁奖活动中&#xff0c;百度创始人、董事长兼首席执行官李彦宏指出&#xff0c;百度一直坚信技术可以改变世界&#xff0c;会一直沿着这条路…

leetcode算法笔记-算法复杂度

对于时间复杂度&#xff0c;主要包括三种情况&#xff1a; 渐进紧确界&#xff1a; O渐进上界&#xff1a; 渐进下界&#xff1a; 加法原则&#xff1a;不同的时间复杂度相加取阶数最高的 乘法原则&#xff1a;不同的时间复杂度相乘&#xff0c;结果为时间复杂度的乘积 阶乘…

环保访谈|浙江双视专注红外机器视觉及智能化应用,保障安全生产

近期&#xff0c;中联环保圈希姐采访了浙江双视科技股份有限公司环保行业销售总监孙波&#xff0c;深入了解了双视科技的发展历程、产品和解决方案、合作流程、核心竞争力以及未来规划。 双视于2014年创立&#xff0c;专注于红外机器视觉、人工智能技术与应用开发&#xff0c;…

前端组件库图片上传时候做自定义裁剪操作

不论是vue还是react项目&#xff0c;我们在使用antd组件库做上传图片的时候&#xff0c;有一个上传图片裁剪的功能&#xff0c;但是这个功能默认是只支持1:1的裁剪操作&#xff0c;如何做到自定义的裁剪操作&#xff1f;比如显示宽高比&#xff1f;是否可以缩放和旋转操作&…

springboot整合redis多数据源(附带RedisUtil)

单数据源RedisUtil(静态) 单数据源RedisUtil,我这里implements ApplicationContextAware在setApplicationContext注入redisTemplate,工具类可以直接类RedisUtil.StringOps.get()使用 package com.vehicle.manager.core.util;import com.alibaba.fastjson.JSON; import lombok.e…

React 第三十章 前端框架的分类

现代前端框架&#xff0c;有一个非常重要的特点&#xff0c;那就是基于状态的声明式渲染。如果要概括的话&#xff0c;可以使用一个公式&#xff1a; UI f&#xff08;state&#xff09; state&#xff1a;当前视图的一个状态f&#xff1a;框架内部的一个运行机制UI&#xff1…

气膜这种建筑节能吗—轻空间

随着社会的发展&#xff0c;气膜建筑逐渐成为人们关注的焦点。其独特的结构和材料使其在节能方面展现出显著的优势。轻空间将从材料和设备两个方面为您介绍气膜建筑的节能特点。 材料&#xff1a;高效隔热与透光 气膜建筑的膜材料选用了聚脂纤维和玻璃纤维等高强度、柔韧性好的…

C语言——预处理详解

目录 ​编辑 一、预定义符号 二、#define定义符号&#xff08;常量&#xff09; 三、define定义宏 四、带有副作⽤的宏参数 五、宏替换的规则 六、宏函数的对比 七、#和## 7.1 #运算符 7.2 ##运算符 八、命名约定 九、#undef 十、命令行定义 十一、条件编译 十二…

MMdetection在Featurize服务器运行时相关问题

写点闲话&#xff1a; 之前因为毕业&#xff0c;想写代码再也没有稳定的机子跑了&#xff0c;自己电脑有时候也带不动&#xff0c;所以开始使用Featurize&#xff0c;这里可以租一些显卡来用&#xff0c;价格总体来说对我们这种偶尔有大规模算力需求的打工人非常友好。使用方法…

Canoe/Canalyzer中加载DLL文件“自动“解锁UDS诊断27服务

点击返回「《UDS/OBD诊断需求编辑工具》总目录」 目录 1 如何在CanOe / Canalyzer中加载“DLL动态链接库文件” 2 如何制作该“DLL动态链接库文件” 2.1 如何获取“DLL动态链接库文件”的DEMO 2.2 使用Visual Studio打开“DLL动态链接库文件”的DEMO 2.2.1 API接口参数说…

TalkingGaussian:基于高斯溅射的结构保持3D说话人头合成

TalkingGaussian: Structure-Persistent 3D Talking Head Synthesis via Gaussian Splatting TalkingGaussian&#xff1a;基于高斯溅射的结构保持3D说话人头合成 Jiahe Abstract 摘要 TalkingGaussian: Structure-Persistent 3D Talking Head Synthes…

Python专题:十二、再谈函数

Python的函数 print&#xff08;&#xff09;函数 def函数名&#xff08;*参数&#xff09; 一次传入多个参数&#xff0c;并保存在元组中 参数混用&#xff0c;普通的参数最好放在不限个数的特殊参数之前 def函数名&#xff08;**参数&#xff09;一次传入多个参数&#x…

【话题】你用过最好用的AI工具有那些

大家好&#xff0c;我是全栈小5&#xff0c;欢迎阅读小5的系列文章&#xff0c;这是《话题》系列文章 目录 背景一、C知道二、CSDN工具集三、AI工具的普及与受欢迎程度四、AI工具的实际应用与影响五、总结与展望文章推荐 背景 探讨人们在使用AI工具时&#xff0c;最喜欢的和认…

【Linux】什么是进程?

一个正在执行的程序&#xff0c;我们称之为进程。 然后我们来顺着一条线来思考。 操作系统底层是用C语言编写的&#xff0c;而我们的进程&#xff0c;它会有各种属性&#xff0c;那么各种属性就可以用一个结构体来对进程的各个属性进行描述&#xff0c;然后这个结构体里面&…

无人机+三角翼:小摩托无人机技术详解

无人机与三角翼的结合&#xff0c;为航空领域带来了一种新型且独特的飞行器——“小摩托”无人机。这种无人机结合了无人机的灵活性和三角翼的飞行稳定性&#xff0c;成为了航空运动领域中的一款热门产品。以下是对“小摩托”无人机技术的详解&#xff1a; 1. 定义与特点&#…