1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #include "CustomMessageDlg.h"
- #include "ui_CustomMessageDlg.h"
- CustomMessageDlg::CustomMessageDlg(QWidget *parent)
- : QDialog(parent)
- , ui(new Ui::CustomMessageDlg)
- {
- ui->setupUi(this);
- this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Dialog);
- }
- CustomMessageDlg::~CustomMessageDlg()
- {
- delete ui;
- }
- void CustomMessageDlg::mousePressEvent(QMouseEvent* event)
- {
- if(event->button() == Qt::LeftButton && event->pos().y() <= 48)
- {
- m_isTitleBarClicked = true;
- m_dragPosition = event->globalPos() - frameGeometry().topLeft();
- event->accept();
- }
- else
- {
- m_isTitleBarClicked = false;
- QDialog::mousePressEvent(event);
- }
- }
- void CustomMessageDlg::mouseMoveEvent(QMouseEvent* event)
- {
- if(m_isTitleBarClicked && (event->buttons() & Qt::LeftButton))
- {
- move(event->globalPos() - m_dragPosition);
- event->accept();
- }
- else
- {
- QDialog::mouseMoveEvent(event);
- }
- }
- void CustomMessageDlg::on_tCloseBut_clicked()
- {
- on_closeBut_clicked(); // TODO: 都交给它
- }
- void CustomMessageDlg::on_closeBut_clicked()
- {
- this->close();
- }
|