蓝色星晨|C/C++编程笔记:无边框窗口橡皮筋拉伸效果( 三 )

< w)r.setX(dx-w);}else if (m_type == Bottom) {r = QRect(p->pos(), QSize(width(), e->pos().y()));if (r.height() < h)r.setHeight(h);}else if (m_type == Top) {r = QRect(p->pos().x(), QCursor::pos().y(), width(), p->pos().y() + height() - QCursor::pos().y());int dy = r.y() + r.height();if (r.height() < h)r.setY(dy-h);}else if (m_type == RightTop) {r = QRect(p->pos().x(), QCursor::pos().y(), e->pos().x(), p->pos().y() + height() - QCursor::pos().y());if (r.width() < w)r.setWidth(w);int dy = r.y() + r.height();if (r.height() < h)r.setY(dy-h);}else if (m_type == LeftTop) {r = QRect(QCursor::pos(), QSize(p->pos().x() + width() - QCursor::pos().x(), p->pos().y() + height() - QCursor::pos().y()));int dx = r.x() + r.width();if (r.width() < w)r.setX(dx-w);int dy = r.y() + r.height();if (r.height() < h)r.setY(dy-h);}else if (m_type == RightBottom) {r = QRect(p->pos(), QCursor::pos());//QSize(e->pos().x(), e->pos().y())));if (r.width() < w)r.setWidth(w);if (r.height() < h)r.setHeight(h);}else if (m_type == LeftBottom) {r = QRect(QCursor::pos().x(), p->pos().y(), p->pos().x() + width() - QCursor::pos().x(), e->pos().y());int dx = r.x() + r.width();if (r.width() < w)r.setX(dx-w);if (r.height() < h)r.setHeight(h);}else return;m_rubber.show();m_rubber.setRect(r);}}elseQWidget::mouseMoveEvent(e);}void CFrameForm::mouseReleaseEvent(QMouseEvent *e) // 鼠标释放后隐藏橡皮筋并设置界面大小{if (m_rubber.isVisible()) {m_rubber.hide();if (m_parent) m_parent->setGeometry(m_rubber.rect());resize(m_rubber.rect().size());}elseQWidget::mousePressEvent(e);m_type = Other;m_pos = QPoint();}void CFrameForm::showEvent(QShowEvent *event) { if (m_parent) resize(m_parent->size()); }void CFrameForm::resizeEvent(QResizeEvent *e) // 窗体大小变更后 , 更新8个区域位置{QWidget::resizeEvent(e);for (int i = 0; i < m_handles.size(); i++) {setHandel(m_handles[i], (Type)m_handles[i]->type());m_handles[i]->raise();}}总结我的砖就抛到这里 , 希望对你们有用 。
【蓝色星晨|C/C++编程笔记:无边框窗口橡皮筋拉伸效果】接下来的路就请各位小伙伴们自己走了!