Monday, October 08, 2007

Qt4 Tux Example

main.cpp

#include "console883.h"

#include
#include


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString fn = "tux.png";

if ( ! QFile::exists( fn ) )
exit( 1 );

Console883 w(0,Qt::FramelessWindowHint);
QPixmap pixmap(fn);

QPalette palette;
palette.setBrush(w.backgroundRole(), QBrush(pixmap));
w.setPalette(palette);
w.setFixedSize( pixmap.size() );
w.setMask(pixmap.mask());
w.show();

a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}


--------------------------------------------------------------------------------------------------------------
console883.h

#ifndef CONSOLE883_H
#define CONSOLE883_H

#include
#include
#include "ui_console883.h"

class Console883 : public QWidget
{
Q_OBJECT

public:
Console883(QWidget *parent = 0, Qt::WFlags f = 0);
~Console883();
void show();

protected:
void mousePressEvent( QMouseEvent *);
void mouseMoveEvent( QMouseEvent *);

private:
Ui::Console883Class ui;

QPoint clickPos;
};

#endif // CONSOLE883_H



----------------------------------------------------------------------------------------------------------------
console883.cpp

#include "console883.h"

Console883::Console883(QWidget *parent, Qt::WFlags f)
: QWidget(parent, f)

{
//ui.setupUi(this);
}

Console883::~Console883()
{

}

void Console883::show()
{
ui.setupUi(this);
QWidget::show();
}

void Console883::mousePressEvent( QMouseEvent *e )
{
clickPos = e->pos();
}

void Console883::mouseMoveEvent( QMouseEvent *e )
{
move( e->globalPos() - clickPos );

}





2 comments:

Anonymous said...

Hi, nice example.
Could you upload on your the complete tarball. Thank you.

Anonymous said...

Well said.