版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
版权
Qt专栏收录该内容
8 篇文章0 订阅
订阅专栏
#include
#include
#include
#include
#include
#include
#include
class PainterWidget: public QWidget
{
protected:
void paintEvent(QPaintEvent *);
};
void PainterWidget::paintEvent(QPaintEvent *event)
{
QLabel *label = new QLabel;
label->setPixmap(QPixmap("c:/painterwidget/images/house.png"));
label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); //忽视初始图片值
label->setScaledContents(true); //设置可改变的内容
QScrollArea *scroll=new QScrollArea;
scroll->setWidgetResizable(true);
scroll->setWidget(label);
QHBoxLayout *main=new QHBoxLayout;
main->addWidget(scroll);
setLayout(main);
}
int main(int argc,char **argv)
{
QApplication app(argc,argv);
PainterWidget pWidget;
pWidget.resize(400,400);
pWidget.show();
return app.exec();
}