一个窗口,继承于QWidget,在main函数中设置窗口固定大小,怎样在窗口的指定位置安置一个控件
cpp文件
#include "invoic.h"
invoic::invoic(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
_image.load("../invoic.jpg");
setAutoFillBackground(true);
label = new QLabel(this);label->setGeometry(100,10,180,40);
label->setText("q AAA");
//label->move(3111,222);
//label->setGeometry(11110, 60, 20, 10);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(label);
//hLayout->setGeometry(QRect(1110,60,20,10));
setLayout(hLayout);
}
invoic::~invoic()
{
}
void invoic::resizeEvent(QResizeEvent *event){
QPalette pal(palette());
pal.setBrush(QPalette::Window,QBrush(_image.scaled(event->size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));
setPalette(pal);
QWidget::resizeEvent(event);
}
h文件
#ifndef INVOIC_H
#define INVOIC_H
#include <QtGui/QWidget>
#include <QtCore>
#include <QtGui>
//#include "ui_invoic.h"
class invoic : public QWidget
{
Q_OBJECT
public:
invoic(QWidget *parent = 0, Qt::WFlags flags = 0);
~invoic();
protected:
void resizeEvent(QResizeEvent *);
private:
//Ui::invoicClass ui;
QImage _image;
QLabel *label;
};
#endif // INVOIC_H
man文件
#include <QtGui/QApplication>
#include <QDesktopWidget>
#include "invoic.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
invoic w;
w.setFixedSize(1018,428);
QDesktopWidget *desktop = QApplication::desktop();
w.move((desktop->width() - w.width()) / 2 ,(desktop->height() - w.height()) / 2);
w.show();
return a.exec();
}
[ 此帖被my253629725在2010-02-18 16:35重新编辑 ]