| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "msgwidget.h"
- #include "ui_msgwidget.h"
- #include <QDebug>
- #include "pdu_ctrl.h"
- MSGWidget::MSGWidget(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::MSGWidget)
- {
- ui->setupUi(this);
- setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
- setAttribute(Qt::WA_TranslucentBackground);
- ui->label_Data->setWordWrap(true);
- QString strBKG="";
- #ifdef RS485Type//()
- strBKG="QWidget{background-color: rgb(0, 225, 225);color: rgb(0, 0, 0);}";
- #else
- strBKG="QWidget{background-color: rgb(30, 30, 255);color: rgb(255, 255, 255);}";
- #endif
- this->setStyleSheet(strBKG);
- }
- MSGWidget::~MSGWidget()
- {
- delete ui;
- }
- void MSGWidget::SetText(QString strShow)
- {
- ui->label_Data->setText(strShow);
- }
- void MSGWidget::setFW(int nW)
- {
- int nHightData=ui->label_Data->heightForWidth(nW-10);
- int nHight=ui->label_Warning->heightForWidth(nW-10);
- int nSum=nHightData+nHight+2;
- // 强制处理所有待处理的事件,确保尺寸更新
- QApplication::processEvents();
- ui->label_Data->setFixedSize(nW-10,nHightData);
- ui->label_Warning->setFixedSize(nW-10,nHight);
- //this->setFixedSize(nW-5,nSum+10);
- // 强制更新布局
- this->layout()->activate();
- this->updateGeometry();
- update(); // 可选:强制重绘整个窗口
- qDebug()<<"MSGWidget label_Size"<<ui->label_Data->size().width()<<"X"<<ui->label_Data->size().height();
- qDebug()<<"MSGWidget label2_Size"<<ui->label_Warning->size().width()<<"X"<<ui->label_Warning->size().height();
- qDebug()<<"MSGWidget heightForWidth"<<nHightData;
- qDebug()<<"MSGWidget setFixedSize"<<nW-5<<"X"<<nSum+10;
- //qDebug()<<"MSGWidget FinalFixedSize"<<this->size().width()<<"X"<<this->size().width();
- /*QTimer::singleShot(50, this, [this]() {
- this->update();
- ui->label_Data->update();
- ui->label_Warning->update();
- });*/
- }
|