qt无标题栏设置
1.設(shè)置沒有標(biāo)題欄
this->setWindowFlags(Qt::FramelessWindowHint);2.鼠標(biāo)移動大小
void Dialog::resizeEvent(QResizeEvent *event) {ui->Button->setGeometry(0, 0, (82*this->width())/1366, (48*this->height())/728);ui->Button->move((230*this->width())/1366, (90*this->height())/728);} bool Dialog::nativeEvent(const QByteArray &eventType, void *message, long *result) {Q_UNUSED(eventType);MSG* pMsg = reinterpret_cast<MSG*>(message);if(pMsg->message == WM_NCHITTEST){int xPos = GET_X_LPARAM(pMsg->lParam) - this->frameGeometry().x();int yPos = GET_Y_LPARAM(pMsg->lParam) - this->frameGeometry().y();if(xPos > 0 && xPos < 8 && yPos > 0 && yPos < 6){*result = HTTOPLEFT;return true;}if(xPos > (this->width() - 8) && xPos < this->width() && yPos > 0 && yPos < 6){*result = HTTOPRIGHT;return true;}if(xPos > 0 && xPos < 8 && yPos > (this->height() - 8) && yPos < this->height() ){*result = HTBOTTOMLEFT;return true;}if(xPos > (this->width() - 8) && xPos < this->width() && yPos > this->height() - 8 && yPos < this->height()){*result = HTBOTTOMRIGHT;return true;}if(xPos > 0 && xPos < 8){*result = HTLEFT;return true;}if(xPos > (this->width() - 8) && xPos < this->width()&&yPos>20){*result = HTRIGHT;return true;}if(yPos > 0 && yPos < 6&&xPos<(this->width()-80)){*result = HTTOP;return true;}if(yPos > (this->height() - 8) && yPos < this->height()){*result = HTBOTTOM;return true;}}return false; } 3.設(shè)置背景圖片 QPixmap pixmap = QPixmap("./images/bg.png").scaled(this->size());QPalette palette (this->palette());palette.setBrush(QPalette::Background, QBrush(pixmap));this->setPalette(palette);4.實(shí)現(xiàn)ESC鍵退出
void Dialog2nd::keyPressEvent(QKeyEvent *e) {switch (e->key()) {case Qt::Key_Escape:this.close();break;default:break;} }5.退出彈出確定框
void Dialog::closeEvent(QCloseEvent *event) {int ret = QMessageBox::information(this,tr("提示"),tr("你確定退出該軟件?"),tr("確定"), tr("取消"),0,1);if (ret == 0){event->accept();}else if(ret==1){event->ignore();} }?
?
?
?
?
總結(jié)
- 上一篇: sct文件编写与使用
- 下一篇: MOS管分析