qt无标题栏设置

1.设置没有标题栏

this->setWindowFlags(Qt::FramelessWindowHint);

2.鼠标移动大小

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.设置背景图片
    QPixmap pixmap = QPixmap("./images/bg.png").scaled(this->size());
    QPalette  palette (this->palette());
    palette.setBrush(QPalette::Background, QBrush(pixmap));
    this->setPalette(palette);

4.实现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();
    }
}

 

 

 

 

 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值