linux下QT去掉边框,qt 界面去掉系统边框
這里將告訴您qt 界面去掉系統邊框,具體完成步驟:在qt5框架實現, 新加的界面類繼承該類即可去掉系統默認邊框
該代碼在Qt5框架編輯,使用該類時, 直接繼承這個類就可以了。 實現了拖拽功能和關閉功能,如果需要放大縮小功能, 需自己實現。 1 #ifndef CUSTOMIZE_QWIDGET_H
2 #define CUSTOMIZE_QWIDGET_H
3 #include
4 #include
5
6 class CustomizeQWidget : public QWidget
7 {
8 Q_OBJECT
9 public:
10 explicit CustomizeQWidget(QWidget *parent = 0);
11 ~CustomizeQWidget();
12 public slots:
13 void on_button_close_clicked();
14 private:
15 void paintEvent(QPaintEvent *);
16 void mousePressEvent(QMouseEvent *event);
17 void mouseMoveEvent(QMouseEvent *event);
18 private:
19 QPoint m_last_mouse_position;
20 };
21 #endif // CUSTOMIZE_QWIDGET_H
1 #include "customize_qwidget.h"
2 #include
3 #include
4 #include
5
6 CustomizeQWidget::CustomizeQWidget(QWidget *parent)
7 : QWidget(parent)
8 {
9 this -> setWindowFlags(Qt::FramelessWindowHint);
10 }
11
12 CustomizeQWidget::~CustomizeQWidget()
13 {
14 }
15
16 void CustomizeQWidget::paintEvent(QPaintEvent *)
17 {
18 QStyleOption opt;
19 opt.init(this);
20 QPainter p(this);
21 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
22 }
23
24 void CustomizeQWidget::mousePressEvent(QMouseEvent *event)
25 {
26 if(event->button() == Qt::LeftButton)
27 {
28 m_last_mouse_position = event->globalPos();
29 }
30 }
31
32 void CustomizeQWidget::mouseMoveEvent(QMouseEvent *event)
33 {
34 if (!event->buttons().testFlag(Qt::LeftButton))
35 return;
36 const QPoint position = pos() + event->globalPos() - m_last_mouse_position; //the position of mainfrmae + (current_mouse_position - last_mouse_position)
37 move(position.x(), position.y());
38 m_last_mouse_position = event->globalPos();
39 }
40
41 void CustomizeQWidget::on_button_close_clicked()
42 {
43 this->close();
44 }
qt 界面去掉系統邊框就為您介紹到這里,感謝您關注懶咪學編程c.lanmit.com.
本文地址:https://c.lanmit.com/bianchengkaifa/net/42506.html
總結
以上是生活随笔為你收集整理的linux下QT去掉边框,qt 界面去掉系统边框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html 全景图three,vue中利用
- 下一篇: 数码管显示原理与驱动方式