QT学习笔记2--QT简述

1. Hello,QT

#include <QApplication>
#include <QLabel>


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QLabel *label =  new QLabel("Hello,World");
    

    label->show();

    return app.exec();
}

2. QT信号槽链接

槽函数四要素:
( s e n d e r , s i g n a l , s l o t , s l o t _ f u n c ) (sender,signal,slot,slot\_func) (sender,signal,slot,slot_func)

#include <QApplication>
#include <QLabel>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);


    QPushButton *button = new QPushButton("click to quit");


    QObject::connect(button,SIGNAL(clicked()),&app,SLOT(quit()));
    button->show();

    return app.exec();
}

3. QT布局

下面的程序将滑条和复选框关联起来

三种布局方式:

  • 水平
  • 竖直
  • 网格
QHBoxLayout
QVBoxLayout
QGridLayout
#include <QApplication>
#include <QLabel>
#include <QPushButton>


#include <QHBoxLayout>
#include <QSlider>
#include <QSpinBox>
#include <QWidget>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget *mainWindow = new QWidget();
    mainWindow->setWindowTitle("Enter your age");

    QSpinBox *spinBox = new QSpinBox();

    QSlider *slider = new QSlider(Qt::Horizontal);
    spinBox->setRange(0, 130);
    slider->setRange(0, 130);


    QObject::connect(slider, SIGNAL(valueChanged(int)),spinBox, SLOT(setValue(int)));
    QObject::connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));

    spinBox->setValue(25);

    QHBoxLayout *layout = new QHBoxLayout();
    layout->addWidget(spinBox);

    layout->addWidget(slider);

    mainWindow->setLayout(layout);

    mainWindow->show();

    return app.exec();
}

4. QT助手

可以通过 Q T A s s i s t a n t QT Assistant QTAssistant来查询 a p i api api和对应的类说明。

相关推荐

  1. QT学习笔记2--QT简述

    2024-03-10 00:04:06       51 阅读
  2. Qt学习笔记(一)

    2024-03-10 00:04:06       39 阅读
  3. Qt学习笔记(二)

    2024-03-10 00:04:06       31 阅读
  4. Qt5学习笔记

    2024-03-10 00:04:06       27 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-10 00:04:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-10 00:04:06       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-10 00:04:06       82 阅读
  4. Python语言-面向对象

    2024-03-10 00:04:06       91 阅读

热门阅读

  1. LeetCode 2710.移除字符串中的尾随零

    2024-03-10 00:04:06       40 阅读
  2. 力扣 239. 滑动窗口最大值

    2024-03-10 00:04:06       44 阅读
  3. P10095 [ROIR 2023 Day 1] 斐波那契乘积

    2024-03-10 00:04:06       68 阅读
  4. Druid数据库连接池配置

    2024-03-10 00:04:06       47 阅读
  5. 国内用ChatGPT可以吗

    2024-03-10 00:04:06       46 阅读
  6. Xargs命令详解: 构建和执行命令的必备工具

    2024-03-10 00:04:06       49 阅读
  7. 面试经典150题(101-104)

    2024-03-10 00:04:06       44 阅读
  8. 一个简单的HTML 个人网页

    2024-03-10 00:04:06       44 阅读
  9. 【记录31】elementUI el-tree 虚线、右键、拖拽

    2024-03-10 00:04:06       43 阅读
  10. const关键字不同使用场景

    2024-03-10 00:04:06       43 阅读