/* ======================================================================** main.cpp** ======================================================================**** ======================================================================** Copyright (c) 2007 by Max Schlee** ======================================================================*/ #include <QtGui> // ======================================================================class Window : public QLabel {private: QPoint m_ptPosition; protected: virtual void Window::mousePressEvent(QMouseEvent* pe) { m_ptPosition = pe->pos(); } virtual void Window::mouseMoveEvent(QMouseEvent* pe) { move(pe->globalPos() - m_ptPosition); } public: Window(QWidget* pwgt = 0) : QLabel(pwgt, Qt::FramelessWindowHint | Qt::Window) { }}; // ----------------------------------------------------------------------int main(int argc, char** argv){ QApplication app(argc, argv); Window win; QPixmap pix(":/images/unixoids.png"); win.setPixmap(pix); win.setMask(pix.mask()); win.show(); return app.exec();}
C++ (Qt)class Window : public QLabel {
#include "qtgranitmainwindow.h"#include <QtGui/QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); QtGranitMainWindow w; QPixmap pix("background.png"); w.setPixmap(pix); w.setMask(pix.mask()); w.show(); return a.exec();}
#ifndef QTGRANITMAINWINDOW_H#define QTGRANITMAINWINDOW_H#include <QtGui/QWidget>#include "ui_qtgranitmainwindow.h"class QtGranitMainWindow : public QWidget{ Q_OBJECTpublic: QtGranitMainWindow(QWidget *parent = 0, Qt::WFlags flags = 0); ~QtGranitMainWindow();private: Ui::QtGranitMainWindowClass ui;};#endif // QTGRANITMAINWINDOW_H
#include "qtgranitmainwindow.h"QtGranitMainWindow::QtGranitMainWindow(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags){ setWindowFlags(Qt::FramelessWindowHint); ui.setupUi(this);}QtGranitMainWindow::~QtGranitMainWindow(){}
C++ (Qt)QPixmap pixmap("F:/tux.png");QLabel *topLevelLabel = new QLabel(this);ui->verticalLayout->addWidget(topLevelLabel);topLevelLabel->setPixmap(pixmap);this->setMask(pixmap.mask());
C++ (Qt)#include <QLabel>#include <QBitmap>
C++ (Qt) this->setAttribute(Qt::WA_TranslucentBackground); this->setWindowFlags(Qt::FramelessWindowHint);