public 下加 void resizeEvent(QResizeEvent *resizeEvent);
代码:
void MainWindow::resizeEvent(QResizeEvent *resizeEvent) { /*ui->mdiArea->setBackground(QBrush(QPixmap(tr("border-image.jpg")).scaled( resizeEvent->size().width(), resizeEvent->size().height()))); */ ui->mdiArea->setBackground(QBrush(QPixmap(tr("border-image.jpg")).scaled( ui->mdiArea->width(), ui->mdiArea->height()))); //以下代码仅为消除警告信息 int d=resizeEvent->size().width(); d++; }
远程下载图片的代码
void MainWindow::border_image(const QString &JpgUrl) { QUrl url(JpgUrl); QNetworkAccessManager manager; QEventLoop loop; QNetworkReply *reply = manager.get(QNetworkRequest(url)); //请求结束并下载完成后,退出子事件循环 QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); //开启子事件循环 loop.exec(); QByteArray gifmsg = reply->readAll(); QString gifname = "border-image.jpg"; QFile file(gifname); if(!file.open(QFile::WriteOnly)) { qDebug() << "open file fail"; exit(1); } file.write(gifmsg); file.close(); }
判断文件是否存在
/*判断文件是否存在*/ bool JCode::isFileExist(QString fullFileName) { QFileInfo fileInfo(fullFileName); if(fileInfo.isFile()) { return true; } return false; }
调用
bool s; s=JCode::isFileExist(fileName); if (s==false){ QString url="http://"+mySQL::ServerWEB; url+="/assets/img/border-image.jpg"; //QMessageBox::warning(this,"警告",url); border_image(url); }
发表评论