QT常用知识点

改变窗体背景色
QPalette palette(this->palette());
palette.setColor(QPalette::Background, polycolor);
this->setPalette(palette);

代码格式化对齐
当前文件全部代码对齐
1ctrl + a
2ctrl + i

获取color
QColor color = lineseries->pen().color();
color = QColorDialog::getColor(color);
QPen pen = lineseries->pen();
pen.setColor(color);
lineseries->setPen(pen);
获取信号槽 button对象做多个按钮不同信号槽处理
QPushButton *m_pushbutton = qobject_cast< QPushButton *>(sender());
int a = QString::compare(m_pushbutton->objectName(),“btnPolylinecolor”);
if(a==0)
qDebug()<<“相等”;
窗体背景和边框去除
setWindowFlags(Qt::FramelessWindowHint|windowFlags());
setAttribute(Qt::WA_TranslucentBackground);
当前线程等待100ms
1 QEventLoop loop;
2 QTimer::singleShot(100, &loop, SLOT(quit()));
3 loop.exec();
QEventLoop
/添加事件循环机制,返回后再运行后面的 http下载
QEventLoop eventLoop;
QNetworkReply *reply = m_pHttpMgr->get(requestInfo);
connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
eventLoop.exec(); //block until finish
//错误处理
if (reply->error() == QNetworkReply::NoError)
{
qDebug() << “request protobufHttp NoError”;
}
else
{
}
读取文件乱码解决 2种方法
QTextCodec *codec = QTextCodec::codecForName(“GBK”);
QString str;
while(file.atEnd()==false)
{
//array += file.readLine();

            QByteArray line = file.readLine();
            str += codec->toUnicode(line);

        }

ui->textEdit->setText(str);

(2) QTextStream stream(&file);
stream.setCodec(“USF-8 or GBK”)

QString str = stream.readall();
i->textEdit->setText(str);

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...