Qt 5笔记

QTabWidget

count

返回tab的数量。返回值:int。计数从1开始。

QString

格式化字符串

arg

“%1, %2”.arg(1, 2)

QImage

cv::Mat to QImage

#include <QtGui/QImage>
// 或者 #include <QImage> 
Mat mat = imread(path);
mat = cvtColor(mat, mat, cv::COLOR_BGR2RGB);
QImage qImage(mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);

QImage to Qpixmap

QPixmap pixMap = QPixmap::fromImaeg(qImage);

显示图像

lable 显示

ui.lable_image->setPixmap(pixMap);
ui.lable_image->setScaledContents(true);
ui.label_image->show();

label 缩放显示

pixMap->scaled(ui.label_Mat->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);

字体

设置中文台字体

//先设置英文字体,再设置英文字体
QFont font;
font_.setFamilies({ QString("TimesNewRoman"),QString("宋体") });

设置整个软件字体

QApplication::setFont(font);

TreeWidget

使用TreeItem继承来确定树的分支关系;
按实例化的顺序确定显示顺序。

SpinBox

输入完全后才响应:setKeyboardTracking(false)

注册Qt未定义类型

qRegisterMetaType<newType>("newType");

QMessageBox

模态窗口

模态窗口显示在界面最顶层,不能操作其他界面。

	QMessageBox *msg_box = new QMessageBox(this);
	msg_box->exec();

非模态窗口

QMessageBox *msg_box = new QMessageBox;
msg_box->show();

固定大小

msg_box->setStyleSheet("QLabel{"
		"min-width:  360px;"
		"min-height: 200px; "
		"font-size:  20px;"
		"}");

弹窗后按键将失去响应,暂时还未找到方法

QSpinBox || QDoubleSpinbox

按键输入完整后响应:setKeyboardTracking(false)

UI操作都只能在主线程

重新connect QDoubleSpinBox/ QSpinBox

QObject::connect(gui_->spinBox_runSpeedHigh, QOverload<int>::of(&QSpinBox::valueChanged), this, &MotionControl::spinBox_runSpeedHigh_valueChanged);
QObject::connect(gui_->doubleSpinBox_initZ1, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &Board::doubleSpinBox_initZ1_valueChanged);

中文读取与写入

gui_->pushButton_estop->setText(QString::fromLocal8Bit("急停中"));
QString text = ui->lineEdit_->text().toLocal8Bit();

检查当前线程是否与主线程相同

#include <QApplication>
#include <QThread>
#include <QDebug>

void checkIfMainThread() {
    if (QThread::currentThread() == QApplication::instance()->thread()) {
        qDebug() << "This is the main thread.";
    } else {
        qDebug() << "This is NOT the main thread.";
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值