下面内容是Linux 窗口程序设计一书中关于QT 不规则窗口程序部分请大家帮忙看看为什么我使用
Qt4.7.0编译成功后却没有显示??
//头文件部分
#ifndef SHAPEWIDGET_H
#define SHAPEWIDGET_H
#include <QtGui>
class QPoint;
class ShapeWidget : public QWidget
{
Q_OBJECT
public:
ShapeWidget(QWidget *parent=0);
protected:
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void paintEvent(QPaintEvent *);
private:
QPoint dragPosition;
//QPainterPath path;
QPainterPath pix;
QPalette palette;
QWidget *frame;
};
#endif // SHAPEWIDGET_H
//功能函数实现
#include "shapewidget.h"
#include "ui_shapewidget.h"
#include <QBitmap>
#include <QPicture>
#include "shapewidget.h"
ShapeWidget::ShapeWidget(QWidget *parent)
: QWidget(parent,Qt::FramelessWindowHint)
{
QPixmap pix;
pix.load(":/images/tux.png",0,Qt::AvoidDither|Qt::ThresholdDither|Qt::ThresholdAlphaDither);
resize(pix.size());
setMask(pix.mask());
}
void ShapeWidget::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
{
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
if (event->button() == Qt::RightButton)
{
close();
}
}
void ShapeWidget::mouseMoveEvent(QMouseEvent * event)
{
if (event->buttons() & Qt::LeftButton)
{
move(event->globalPos() - dragPosition);
event->accept();
}
}
void ShapeWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(0,0,QPixmap(":/tux.png"));
}
//main 函数
#include <QApplication>
#include "shapewidget.h"
int main(int argc, char * argv[])
{
QApplication app(argc,argv);
ShapeWidget shape;
//app.setMainWidget(&shape);
shape.show();
return app.exec();
}
请大家帮我看看,先谢了!!