用Qt實現窗體的無邊框、可移動、透明不規則顯示(需背景透明的圖片)
阿新 • • 發佈:2019-01-05
用Qt可以做出很炫的介面,更多的功能還有待學習^_^!
1、建構函式中需要做的設定:
[cpp] view plaincopyprint?- this->setWindowOpacity(1);//設定窗體不透明
- this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);//設定窗體無邊框,允許工作列按鈕右鍵選單
- this->setAttribute(Qt::WA_TranslucentBackground);//設定背景透明
-
mouseMovePos = QPoint(0, 0);
- movie->setFileName(":/new/prefix1/welcome.gif");
- ui->label->setMovie(movie);
- ui->label->setScaledContents(true);
- movie->start();
2、滑鼠移動和點選事件的設定:
[cpp] view plaincopyprint?- //滑鼠按下並移動則移動不規則窗體
- void Menu::mouseMoveEvent(QMouseEvent *event)
-
{
- if(mouseMovePos != QPoint(0, 0))
- {
- move(geometry().x() + event->globalPos().x() - mouseMovePos.x(),
- geometry().y() + event->globalPos().y() - mouseMovePos.y());
- mouseMovePos = event->globalPos();
- }
- }
-
void Menu::mousePressEvent(QMouseEvent *event)
- {
- mouseMovePos = event->globalPos();
- }
- void Menu::mouseReleaseEvent(QMouseEvent *event)
- {
- mouseMovePos = QPoint(0, 0);
- }
FROM: http://blog.csdn.net/gtopia/article/details/9666817