#include <QApplication>
#include <QWidget>
#include <QPixmap>
#include <QBitmap>
#include <QPoint>
#include <QPalette>
#include <QMouseEvent>
#include <QPainter>
{
public:
protected:
private:
};
: QWidget(parent,Qt
::X11BypassWindowManagerHint) {
setGeometry(200,200,800,120);
brush->setStyle(Qt::SolidPattern) ;
brush->setColor(Qt::gray) ;
//painter->setBackgroundMode(Qt::OpaqueMode);
painter->begin(this) ;
painter->setBackground(*brush) ;
painter->setPen(Qt::red) ;
painter->drawEllipse(10,0,10,10) ;//画了一个小圆圈,运行时可见。
painter->end() ;
setPalette(palette);
setMask(*pixmap);
}
{
if (!(e->buttons() & Qt::LeftButton))
return;
QPoint newpos
= e
->globalPos
();
QPoint upleft
= pos0
+ newpos
- last;
move(upleft);
}
{
if (e->button() == Qt::LeftButton)
last = e->globalPos();
pos0 = e->globalPos() - e->pos();
}
int main(int argc,char *argv[])
{
myclass w;
w.showFullScreen();
return a.exec();
}
#include <QApplication>
#include <QWidget>
#include <QPixmap>
#include <QBitmap>
#include <QPoint>
#include <QPalette>
#include <QMouseEvent>
#include <QPainter>
class myclass:public QWidget
{
public:
myclass(QWidget *parent = 0);
protected:
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
private:
QPixmap *pixmap;
QBitmap *bitmap;
QPainter *painter ;
QBrush *brush ;
QPoint last,pos0;
};
myclass::myclass(QWidget *parent)
: QWidget(parent,Qt::X11BypassWindowManagerHint)
{
setGeometry(200,200,800,120);
brush =new QBrush();
brush->setStyle(Qt::SolidPattern) ;
brush->setColor(Qt::gray) ;
pixmap=new QPixmap(800,120);
painter =new QPainter(pixmap) ;
//painter->setBackgroundMode(Qt::OpaqueMode);
painter->begin(this) ;
painter->setBackground(*brush) ;
painter->setPen(Qt::red) ;
painter->drawEllipse(10,0,10,10) ;//画了一个小圆圈,运行时可见。
painter->end() ;
QPalette palette;
palette.setBrush(QPalette::Background, QBrush(*pixmap));
setPalette(palette);
setMask(*pixmap);
}
void myclass::mouseMoveEvent(QMouseEvent *e)
{
if (!(e->buttons() & Qt::LeftButton))
return;
QPoint newpos = e->globalPos();
QPoint upleft = pos0 + newpos - last;
move(upleft);
}
void myclass::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
last = e->globalPos();
pos0 = e->globalPos() - e->pos();
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
myclass w;
w.showFullScreen();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks