|
发表于 2006-2-21 14:24:14
|
显示全部楼层
我是初学者,谢谢提示。
另外我按这篇文章手工写了界面程序,只是该程序只能在命令行运行,如果在KDE下双击运行的话,窗体还是四方的,何解?
我找了很多资料了,苦无结果,我把代码贴出来,希望能得到指点:
[code:1]
#include <qapplication.h>
#include <qwidget.h>
#include <qpixmap.h>
#include <qbitmap.h>
#include <qpoint.h>
class myclass:public QWidget
{
public:
myclass(QWidget *parent = 0, const char *name = 0 );
protected:
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
private:
QPixmap *pixmap;
QBitmap *bitmap;
QPoint oldpos;
};
myclass::myclass(QWidget *parent, const char *name)
: QWidget( parent, name,
Qt::WStyle_Customize | Qt::WStyle_NoBorder)
{
setMaximumSize(120,120);
setMinimumSize(120,120);
move(300,300);
pixmap=new QPixmap("tmp.png");
bitmap=new QBitmap("mask.png");
setPaletteBackgroundPixmap(*pixmap);
setBackgroundOrigin( QWidget::WindowOrigin );
setMask(*bitmap);
if ( autoMask() ){
updateMask();}
}
void myclass::mouseMoveEvent(QMouseEvent *e)
{
if(e->state()==LeftButton)
{
QPoint tmppos;
tmppos=e->pos();
tmppos=pos()+(tmppos-oldpos);
move(tmppos);
}
}
void myclass::mousePressEvent(QMouseEvent *e)
{
oldpos=e->pos();
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
myclass w;
a.setMainWidget(&w);
w.show();
return a.exec();
}
[/code:1] |
|