改变窗体背景色
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);
格式化字符串
QString str = Qstring(-----%1 ----- %2----).arg(xxx).arg(yyy);