qt/LedOK/base/pixbmpshowdialog.cpp

42 lines
1.0 KiB
C++
Raw Normal View History

2023-04-18 14:14:46 +08:00
#include "pixbmpshowdialog.h"
#include "ui_pixbmpshowdialog.h"
#include <QPainter>
PixbmpShowDialog::PixbmpShowDialog(QWidget *parent) :
BaseDlg(parent),
ui(new Ui::PixbmpShowDialog)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
}
PixbmpShowDialog::~PixbmpShowDialog()
{
delete ui;
}
void PixbmpShowDialog::ResizeByPixmap(int w,int h)
{
m_iWidth=w;
m_iHeight=h;
int iWidth=w;
int iHeight=h;
if(iWidth<rect().width()&&iHeight<rect().height())
this->resize(iWidth,iHeight);
else {
if(iWidth>iHeight)
this->resize(rect().height()*iWidth/iHeight,rect().height());
else
this->resize(rect().width(),rect().width()*iHeight/iWidth);
}
}
void PixbmpShowDialog::paintEvent(QPaintEvent * event)
{
Q_UNUSED(event);
QPainter painter(this);
//painter.eraseRect(rect());
// painter.scale(m_PixMap.width(), m_PixMap.height());
QRectF sourceRt(0,0,m_iWidth,m_iHeight);
painter.drawPixmap(rect(), m_PixMap,sourceRt);
}