#include "DeviceWidget.h" #include #include #include #include DeviceWidget::DeviceWidget(const DeviceInfo &device, QWidget *parent): QWidget(parent) { auto *layout = new QVBoxLayout(this); this->setStyleSheet("background-color: lightgray;padding: 10px;"); QImage img; img.loadFromData(device.image, "JPG"); auto *imageLabel = new QLabel(this); qDebug() << "imageLabel" << img.width() ; imageLabel->setPixmap(QPixmap::fromImage(img).scaled(200, 350, Qt::KeepAspectRatio, Qt::SmoothTransformation)); imageLabel->setAlignment(Qt::AlignCenter); layout->addWidget(imageLabel); const QString result = QString("%1, Android %2, battery %3% [%4x%5]") .arg(device.name).arg(device.android).arg(device.battery). arg(device.screenWidth).arg(device.screenHeight); auto *statusLabel = new QLabel(result, this); statusLabel->setAlignment(Qt::AlignCenter); statusLabel->setMaximumWidth(200); statusLabel->setWordWrap(true); const QString styleSheet = QString("color: %1; font-weight: bold;") .arg(device.status == "online" ? "green" : "red"); statusLabel->setStyleSheet(styleSheet); // layout->setContentsMargins(10, 10, 10, 10); layout->setSpacing(0); layout->addWidget(statusLabel); }