42 lines
1.0 KiB
C++
42 lines
1.0 KiB
C++
|
#include "MainWindow.h"
|
|||
|
|
|||
|
#include <QMessageBox>
|
|||
|
#include <QVBoxLayout>
|
|||
|
#include <QLabel>
|
|||
|
|
|||
|
#include "FileHelper.h"
|
|||
|
#include "NetClient.h"
|
|||
|
|
|||
|
#include "ui_MainWindow.h"
|
|||
|
|
|||
|
MainWindow::MainWindow(QWidget *parent) :
|
|||
|
QMainWindow(parent),
|
|||
|
ui(new Ui::MainWindow)
|
|||
|
{
|
|||
|
ui->setupUi(this);
|
|||
|
|
|||
|
qint16 port = 9528;
|
|||
|
|
|||
|
m_netClient = new NetClient(this);
|
|||
|
if (!m_netClient->Start(port)) {
|
|||
|
QMessageBox::warning(this, tr("error"), tr("config failed"));
|
|||
|
qApp->quit();
|
|||
|
}
|
|||
|
connect(m_netClient, &NetClient::FileReady, this, &MainWindow::ShowItemImage);
|
|||
|
}
|
|||
|
|
|||
|
MainWindow::~MainWindow() {
|
|||
|
m_netClient->Stop();
|
|||
|
delete ui;
|
|||
|
}
|
|||
|
|
|||
|
void MainWindow::ShowItemImage(const QString& filePath) {
|
|||
|
QPixmap pixmap(filePath);
|
|||
|
|
|||
|
// 设置 QLabel 的样式表,将下载的图片作为背景图片,并重复平铺
|
|||
|
QString styleSheet = QString("QLabel { background-image: url(path/to/image.jpg); "
|
|||
|
"background-repeat: repeat; }");
|
|||
|
styleSheet.replace("path/to/image.jpg", filePath);
|
|||
|
ui->lb_image->setStyleSheet(styleSheet);
|
|||
|
}
|