Qt 技巧:去除對話框邊框 + 設置窗口可移動和透明


1、去除對話框標題欄和邊框
在構造函數里設置:
    this->setWindowFlags(Qt::FramelessWindowHint);

Qt::Dialog     (按照對話框的形式創建窗口--幫助/關閉)
Qt::Window  (按照正常窗口的形式創建窗口--最大化/最小化/關閉)
 
2、窗口可移動
去除邊框會造成窗口不可移動,可以通過以下方法來解決:
自定義鼠標按下事件和鼠標移動事件:
void yourwindow::mousePressEvent(QMouseEvent *event)
{
     this->windowPos = this->pos();                // 獲得部件當前位置
     this->mousePos = event->globalPos();     // 獲得鼠標位置
     this->dPos = mousePos - windowPos;       // 移動后部件所在的位置
}
 
void yourwindow::mouseMoveEvent(QMouseEvent *event)
{
     this->move(event->globalPos() - this->dPos);
}
 
3、設置窗口透明
在構造函數中添加:
    this->setAttribute(Qt::WA_TranslucentBackground);

http://blog.csdn.net/jan5_reyn/article/details/38955695


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM