CustomMessageDlg.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "CustomMessageDlg.h"
  2. #include "ui_CustomMessageDlg.h"
  3. CustomMessageDlg::CustomMessageDlg(QWidget *parent)
  4. : QDialog(parent)
  5. , ui(new Ui::CustomMessageDlg)
  6. {
  7. ui->setupUi(this);
  8. this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Dialog);
  9. }
  10. CustomMessageDlg::~CustomMessageDlg()
  11. {
  12. delete ui;
  13. }
  14. void CustomMessageDlg::mousePressEvent(QMouseEvent* event)
  15. {
  16. if(event->button() == Qt::LeftButton && event->pos().y() <= 48)
  17. {
  18. m_isTitleBarClicked = true;
  19. m_dragPosition = event->globalPos() - frameGeometry().topLeft();
  20. event->accept();
  21. }
  22. else
  23. {
  24. m_isTitleBarClicked = false;
  25. QDialog::mousePressEvent(event);
  26. }
  27. }
  28. void CustomMessageDlg::mouseMoveEvent(QMouseEvent* event)
  29. {
  30. if(m_isTitleBarClicked && (event->buttons() & Qt::LeftButton))
  31. {
  32. move(event->globalPos() - m_dragPosition);
  33. event->accept();
  34. }
  35. else
  36. {
  37. QDialog::mouseMoveEvent(event);
  38. }
  39. }
  40. void CustomMessageDlg::on_tCloseBut_clicked()
  41. {
  42. on_closeBut_clicked(); // TODO: 都交给它
  43. }
  44. void CustomMessageDlg::on_closeBut_clicked()
  45. {
  46. this->close();
  47. }