bool GridWidget::eventFilter(QObject *object, QEvent *e){ if (object == m_moveButton) { if (e->type() == QEvent::MouseMove) { QMouseEvent *me = static_cast<QMouseEvent *>(e); move(mapToParent(me->pos() - m_offset)); return true; } else if (e->type() == QEvent::MouseButtonPress) { QMouseEvent *me = static_cast<QMouseEvent *>(e); m_offset = me->pos(); return false; } return false; } else if (object == m_resizeButton) { if (e->type() == QEvent::MouseMove) { QMouseEvent *me = static_cast<QMouseEvent *>(e); QPoint sz = me->pos() - m_offset; sz += QPoint(size().width(), size().height()); resize(sz.x(), sz.y()); m_widget->resize(sz.x(), sz.y()); m_resizeButton->move(sz.x() - m_resizeButton->width() - 5, sz.y() - m_resizeButton->height() - 5); return true; } else if (e->type() == QEvent::MouseButtonPress) { QMouseEvent *me = static_cast<QMouseEvent *>(e); m_offset = me->pos(); return false; } return false; } return false;}
m_resizeButton->installEventFilter(this);
void MainWindow::mousePressEvent(QMouseEvent * event){ if (event->pos().x()<605&&event->pos().y()<35&&event->pos().x()>85) { if(event->button() == Qt::LeftButton) { Last_Point = event->pos(); b_move = true; } }}void MainWindow::mouseMoveEvent(QMouseEvent *event){ if (event->pos().x()<605&&event->pos().y()<35&&event->pos().x()>85) { if((event->buttons() & Qt::LeftButton) && b_move) move(event->globalX()-Last_Point.x(), event->globalY()-Last_Point.y()); } }void MainWindow::mouseReleaseEvent(QMouseEvent *event){ if (event->button() == Qt::LeftButton && b_move) { b_move = false; }}
QRect rect(0,0,685,450); this->setMask(rect);
setWindowFlags(Qt::FramelessWindowHint); ui->setupUi(this); ui->mainToolBar->setVisible(0); ui->statusBar->setVisible(0); ui->menuBar->setVisible(0); QPixmap pix(":/1.png"); ui->label->setPixmap(pix); ui->label->setScaledContents(1); QRect rect(0,0,685,450); this->setMask(rect);
QLabel l("asdasdasdasd");l.setPixmap(QPixmap("C://a.jpg"));GridWidget w;w.setWidget(&l);w.setWindowFlags(Qt::FramelessWindowHint);w.setMask(QRegion(0, 0, 685, 450));w.show();