imgBtnClose = new QPixMap(":/wndMain/btnClose.png");
#ifndef CMAINWINDOW_H#define CMAINWINDOW_H#include <QMainWindow>#include <QtGui>class cMainWindow:public QMainWindow{ Q_OBJECTpublic: cMainWindow(QWidget *parent=0); ~cMainWindow();private: virtual void resizeEvent(QResizeEvent *event); virtual void paintEvent(QPaintEvent *event); virtual void mousePressEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event); int intWndLostNowPos [1]; bool wndDrugOrNO; QPixmap *pixMainFon;};#endif // CMAINWINDOW_H
#include "cMainWindow.h"#include <QBitmap>#include <QPainter>cMainWindow::cMainWindow(QWidget *parent):QMainWindow(parent){ pixMainFon=new QPixmap(":/wndMain/wndMain.png"); this->setGeometry(pixMainFon->rect());}cMainWindow::~cMainWindow(){}void cMainWindow::resizeEvent(QResizeEvent *event){ this->setMask(pixMainFon->mask());}void cMainWindow::paintEvent(QPaintEvent *event){ QRegion paintWndMainRegion(pixMainFon->rect()); QPainter painter(this); painter.setClipRegion(paintWndMainRegion); painter.drawPixmap(pixMainFon->rect(),*pixMainFon);}void cMainWindow::mousePressEvent(QMouseEvent *event){wndDrugOrNO=true;intWndLostNowPos[0]=event->x();intWndLostNowPos[1]=event->y();}void cMainWindow::mouseReleaseEvent(QMouseEvent *event){wndDrugOrNO=false;}void cMainWindow::mouseMoveEvent(QMouseEvent *event){ //********** if (wndDrugOrNO){ if (event->x()>intWndLostNowPos[0]){ this->move(this->x()+(event->x()-intWndLostNowPos[0]),this->y()); } if (event->x()<intWndLostNowPos[0]){ this->move(this->x()-(intWndLostNowPos[0]-event->x()),this->y()); } if (event->y()>intWndLostNowPos[1]){ this->move(this->x(),this->y()+(event->y()-intWndLostNowPos[1])); } if (event->y()<intWndLostNowPos[1]){ this->move(this->x(),this->y()-(intWndLostNowPos[1]-event->y())); } } //**********}
#ifndef CMAINCLOSEBUTTON_H#define CMAINCLOSEBUTTON_H#include <QWidget>#include <QtGui>class cMainCloseButton:public QWidget{ Q_OBJECTpublic: cMainCloseButton(QWidget *parent=0); ~cMainCloseButton();private: virtual void resizeEvent(QResizeEvent *event); virtual void paintEvent(QPaintEvent *event); QImage *imgBtnClose;};#endif // CMAINCLOSEBUTTON_H
#include "cMainCloseButton.h"#include <QPainter>#include <QImage>cMainCloseButton::cMainCloseButton(QWidget *parent):QWidget(parent){ imgBtnClose = new QImage(":/wndMain/btnClose.png"); //Вот это кладет все, закомментируешь и все пучком )}cMainCloseButton::~cMainCloseButton(){}void cMainCloseButton::resizeEvent(QResizeEvent *event){ //this->setMask(imgBtnClose.mask());}void cMainCloseButton::paintEvent(QPaintEvent *event){ // QRegion btnCloseRegion(imgBtnClose.rect()); // QPainter painter(this); // painter.setClipRegion(btnCloseRegion); // painter.drawPixmap(imgBtnClose.rect(),&imgBtnClose);}
int intWndLostNowPos [1];intWndLostNowPos[0]=event->x();intWndLostNowPos[1]=event->y();
C++ (Qt)...cMainCloseButton(QWidget *parent=0, const QPixmap &pix = QPixmap());...cMainCloseButton::cMainCloseButton(QWidget *parent, QPixmap &pix):QWidget(parent){ m_pixmap = pix;}...painter.drawPixmap(rect(), m_pixmap);...