Qt无边框窗口的“关闭”和“移动”
2016-05-10 15:04
330 查看
Qt在设计过程中,经常遇到无边框界面设计和鼠标拖拽移动,当点击自定义的“关闭”按钮时如何真正退出和实现窗口移动是一个常用的功能:
关于“关闭/退出”:
this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); //不用Qt::SubWindow。 QPushButton *pb = new QPushButton(this); pb->setText(tr("关闭")); connect(pb,SIGNAL(clicked()),this,SLOT(close()));
关于“鼠标拖动”:
//QMoveTest.h void mousePressEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e); QPoint startRelativePos; //QMoveTest.cpp void QMoveTest::mousePressEvent(QMouseEvent *e) { if (e->buttons() == Qt::LeftButton) startRelativePos = e->pos(); } void QMoveTest::mouseMoveEvent(QMouseEvent *e) { if (e->buttons() & Qt::LeftButton) move(e->globalPos() - startRelativePos); } void QMoveTest::mouseReleaseEvent(QMouseEvent *e) { e->accept(); }
示例:
相关文章推荐
- Qt之自定义界面(实现无边框、可移动)
- Qt之自定义界面(添加自定义标题栏)
- Qt之自定义界面(窗体缩放)
- Qt之自定义界面(QMessageBox)
- Qt之窗体拖拽、自适应分辨率、自适应大小
- 24位RGB数据保存为BMP图片
- Qt QPainter::end: Painter ended whith 2 saced states
- Qt之自定义搜索框
- Qt中使用QSS设计风格
- qt QTableView 的使用(嵌入QCheckobox,为某一单元格设置颜色,单击,双击,右键菜单QMenu)
- qt的字体和颜色设置对话框
- ubuntu qt QTableWidget
- Some Tips and Tricks about Qt
- Some Tips and Tricks about Qt
- qt打开含有中文字符链接
- Qt: 创建具有复选框的树形控件
- QT中常见的问题总结系列
- Qt Creator 配置Msvc 2012的调试器
- QT5.5.1+VS2013+OpenGL+OpenCV
- QT源代码阅读