大二暑期实习记录

1.QT 关闭主窗口时触发关闭所有打开的其他窗口

1.用的信号/槽实现
在main函数中将QApplication::lastWindowClosed()信号和QApplication::quit()槽函数相关联
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
void QApplication::lastWindowClosed () [signal] 后面有QT助手的解释,
明显没有我的方法简单方便

2.设置窗口参数 Qt::WA_QuitOnClose attribute,为true 的所有窗口关闭后程序退出.
主窗口设置属性Qt::WA_QuitOnClose : this.setAttribute(Qt::WA_QuitOnClose,true);
其他窗口设置属性Qt::WA_QuitOnClose : this.setAttribute(Qt::WA_QuitOnClose,false);
这样关闭主窗口的时候,主程序就会退出,其他窗口也会关闭。

3.这两步就完成了任务.不过为了方便,我们可以把其他窗口类的构造函数中加一句
setAttribute(Qt::WA_QuitOnClose,false); 这样就不用为每个生成的窗体添加属性了.

2.Qt QLineEdit限制为英文输入法

在设计登录界面的时候,账号和密码是需要禁止输入法输入的,所以需要对相应QLineEdit进行设置

ui->account->setAttribute(Qt::WA_InputMethodEnabled, false);
ui->password->setAttribute(Qt::WA_InputMethodEnabled, false);

3.qcustomplot清除已绘制的所有图形

解决思路:
利用clearGraphs()清除所有的graph,然后再刷新qcustomplot界面即可清除。
解决方法:
其中widget是提升过后的qcustomplot类型

ui->widget->clearGraphs();
ui->widget->replot();

4.QT 设置程序图标

4.1 窗口左上角图标和任务栏图标
rabbit.ico位置如图所示
文件结构

this->setWindowIcon(QIcon(":/rabbit.ico"));

4.2 程序图标

.pro文件中新增一行

RC_ICONS = rabbit.ico

然后重新编译即可。

猜你喜欢

转载自blog.csdn.net/CesareBorgia/article/details/118680432
今日推荐