QT入门笔记

记录整理QT学习要点

控件类:

控件类:
1.	Widget

    //设置固定窗口大小
    w.setFixSize(500,300);

2.	QLabel
    
    //设置标签图片
    QPixmap pix("图片地址");
    ui->label->setPixmap(pix);

3.	QPushButton

	//设置按钮贴图
	QIcon con(“图片文件地址”);
	PushButton->setIcon(con);

    //设置按钮背景色
	PushButton->setStyleSheet(“background:blue”);

4.	QLineEdit
    
    //设置输入框字体
    QFont f(“仿宋”,14);
    LineEdit->setFont(f);

函数类:

函数类:
1.	进程类:QProcess

    Process->start(“可执行文件的地址”);
    //startDetached()打开文件夹
     QString path = QCoreApplication::applicationDirPath();
     path.replace("/","\\");//将地址中的"/"替换为"\",因为在Windows下使用的是"\"。
     QProcess *process = new QProcess(this);
     process->startDetached("explorer "+ path);

2.	消息框类:QMessageBox

    QMessageBox::information(this,”窗口标题”,”提示内容”);

3.	槽函数:connect()
    a)	connect(ui->LineEdit,SIGNAL(returnPressed()),this,SLOT(槽函数))//宏调用函数
    b)	connect(ui->LineEdit,&QPushButton::clicked ,this,&Widget::槽函数)//取地址调用函数
    c)	connect(ui->LineEdit,&QPushButton::clicked ,[this](){槽函数})//调用小型函数

4.  QCoreApplication类
    QCoreApplication::applicationDirPath()
    QCoreApplication::applicationFilePath()

5.  QStandardPaths类
    QString str2 = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);

6.  windows.h类
    //打开需要管理员权限的软件
    QString path = QCoreApplication::applicationDirPath();
    QString myexe = (path+"/09-HWiNFO_2023.1.1/HWiNFO64.exe");

    SHELLEXECUTEINFO sei = {sizeof(SHELLEXECUTEINFO)};
    sei.lpVerb = TEXT("runas");
    sei.lpFile = myexe.toStdWString().c_str();
    sei.nShow = SW_SHOWNORMAL;
    if (!ShellExecuteEx(&sei)) ;
7.  QScreen类
    //获取当前屏幕宽度
    QScreen *screen = QGuiApplication::primaryScreen();  //获取主屏幕
    QRect r = screen->geometry();
    int width = r.width();

8.  QT定时器
    //1.头文件放变量、声明虚函数重写
    int myTimerID;

    virtual void timerEvent(QTimerEvent *event);

    //2.widget.cpp启动定时器
    myTimerID = this->startTimer(1000);

    //3. widget.cpp具体虚函数
    void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId() != myTimerID)
        return;
    //写事件
}
    //4. 结束
    this->killTimer(myTimerID);





给exe添加默认桌面图标的方法:

//1.新建一个.rc文件,“新建文件”—“C++ source File”—命名为logo.rc(不能掉了rc后缀)。

//2.然后pro工程文件添加以下内容

#若你已经添加了QT资源文件,以下两条语句只需更改qss名字即可,如果没有则按该名字创建资源文件
#再将icon图标添加到资源

RESOURCES += \
qss.qrc

RESOURCES += \
你的qrc文件的名字.qrc
DISTFILES += \
logo.rc
RC_FILE += logo.rc

学习日志:

第1天:2024-5-9周四,晴

第2天:2024-5-11周六,雨转阴

第3天:2024-5-19周日,晴

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值