当前位置:   article > 正文

qt无标题栏设置_qt怎么把dialog菜单栏删掉

qt怎么把dialog菜单栏删掉

1.设置没有标题栏

this->setWindowFlags(Qt::FramelessWindowHint);

2.鼠标移动大小

  1. void Dialog::resizeEvent(QResizeEvent *event)
  2. {
  3. ui->Button->setGeometry(0, 0, (82*this->width())/1366, (48*this->height())/728);
  4. ui->Button->move((230*this->width())/1366, (90*this->height())/728);
  5. }
  6. bool Dialog::nativeEvent(const QByteArray &eventType, void *message, long *result)
  7. {
  8. Q_UNUSED(eventType);
  9. MSG* pMsg = reinterpret_cast<MSG*>(message);
  10. if(pMsg->message == WM_NCHITTEST){
  11. int xPos = GET_X_LPARAM(pMsg->lParam) - this->frameGeometry().x();
  12. int yPos = GET_Y_LPARAM(pMsg->lParam) - this->frameGeometry().y();
  13. if(xPos > 0 && xPos < 8 && yPos > 0 && yPos < 6){
  14. *result = HTTOPLEFT;
  15. return true;
  16. }
  17. if(xPos > (this->width() - 8) && xPos < this->width() && yPos > 0 && yPos < 6){
  18. *result = HTTOPRIGHT;
  19. return true;
  20. }
  21. if(xPos > 0 && xPos < 8 && yPos > (this->height() - 8) && yPos < this->height() ){
  22. *result = HTBOTTOMLEFT;
  23. return true;
  24. }
  25. if(xPos > (this->width() - 8) && xPos < this->width() && yPos > this->height() - 8 && yPos < this->height()){
  26. *result = HTBOTTOMRIGHT;
  27. return true;
  28. }
  29. if(xPos > 0 && xPos < 8){
  30. *result = HTLEFT;
  31. return true;
  32. }
  33. if(xPos > (this->width() - 8) && xPos < this->width()&&yPos>20){
  34. *result = HTRIGHT;
  35. return true;
  36. }
  37. if(yPos > 0 && yPos < 6&&xPos<(this->width()-80)){
  38. *result = HTTOP;
  39. return true;
  40. }
  41. if(yPos > (this->height() - 8) && yPos < this->height()){
  42. *result = HTBOTTOM;
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  3.设置背景图片
  1. QPixmap pixmap = QPixmap("./images/bg.png").scaled(this->size());
  2. QPalette palette (this->palette());
  3. palette.setBrush(QPalette::Background, QBrush(pixmap));
  4. this->setPalette(palette);

4.实现ESC键退出

  1. void Dialog2nd::keyPressEvent(QKeyEvent *e)
  2. {
  3. switch (e->key()) {
  4. case Qt::Key_Escape:
  5. this.close();
  6. break;
  7. default:
  8. break;
  9. }
  10. }

5.退出弹出确定框

  1. void Dialog::closeEvent(QCloseEvent *event)
  2. {
  3. int ret = QMessageBox::information(this,tr("提示"),tr("你确定退出该软件?"),tr("确定"), tr("取消"),0,1);
  4. if (ret == 0)
  5. {
  6. event->accept();
  7. }
  8. else if(ret==1)
  9. {
  10. event->ignore();
  11. }
  12. }

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/616544
推荐阅读
相关标签
  

闽ICP备14008679号