Qt 自定義的氣泡型別提示視窗

2021-10-09 18:41:10 字數 2704 閱讀 7476

介面定義盡可能的詳細備註到 .h 檔案中。

// arrowwidget.h

#ifndef arrowwidget_h

#define arrowwidget_h

#include

#include

#include

const

int shadow_width =30;

// 視窗陰影寬度;

const

int ********_width =30;

// 小三角的寬度;

const

int ********_height =10;

// 小三角的高度;

const

int border_radius =15;

// 視窗邊角的弧度;

class

arrowwidget

:public qwidget

;// 設定小三角起始位置;

void

setstartpos

(int startx)

;// 設定小三角寬和高;

void

set********info

(int width,

int height)

;// 設定展示文字

void

settext

(qstring s)

;// 設定小三角的位置

void

setderection

(derection d);//

qstring text()

;// 比起左上角的位置 使用者更關心小三角的尖尖的位置 過載move以便使用者更容易定位氣泡框的位置

// x,y 是氣泡視窗小賤賤的座標

void

mymove

(int x,

int y)

;protected

:void

paintevent

(qpaintevent *);

void mousepressevent (qmouseevent *);

private

:// 小三角的偏移量;

int m_offset;

// 小三角的寬度;

int m_********width;

// 小三角高度;

int m_********height;

derection derect;

qlabel *lb_text;};

#endif

// arrowwidget_h

// arrowwidget.cpp

#include

"arrowwidget.h"

#include

#include

#include

#include

#include

#include

arrowwidget::

arrowwidget

(qwidget *parent)

:qwidget

(parent)

,m_offset(50

),m_********width

(********_width)

,m_********height

(********_height)

// 設定小三角顯示的起始位置;

void arrowwidget::

setstartpos

(int startx)

void arrowwidget::

set********info

(int width,

int height)

void arrowwidget::

settext

(qstring s)

void arrowwidget::

setderection

(arrowwidget::derection d)

qstring arrowwidget::

text()

void arrowwidget::

mymove

(int x,

int y)

}void arrowwidget::

paintevent

(qpaintevent*

)break

;case left:

break

;case right:

break

;case down:

break

;default

:break;}

drawpath.

addroundedrect

(myrect, border_radius, border_radius)

; drawpath.

addpolygon

(********polygon)

; painter.

drawpath

(drawpath);}

void arrowwidget::

mousepressevent

(qmouseevent *

)

QT自定義的氣泡型別提示框

由於專案需要,自定義了乙個qt氣泡顯示的控制項,參照了一部分網上的 自己也修改了許多,可支援四個不同的方向。不多說,上圖 如下 const int shadow width 15 視窗陰影寬度 const int width 15 小三角的寬度 const int height 10 小三角的高度 ...

Qt自定義視窗事件

一 移動主介面 移動主介面是通過按住滑鼠左鍵進行標題欄拖動最終導致主介面移動 由於還有視窗伸縮功能,因此對於標題欄左部,頂部,右部應該騰出5畫素空間給視窗伸縮功能使用,即滑鼠移動到這5畫素空間之內的話,滑鼠形狀就會發生改變 暗示可以伸縮視窗 為什麼只有標題欄騰出5畫素空間,而其他部件 如工具欄 內容...

Qt註冊自定義型別

如果要在qt訊號槽中使用自定義型別,需要注意使用qregistermetatype對自定義型別進行註冊,當然在不跨執行緒時使用自定義型別signal slot來傳遞,可能不會出現什麼問題 一旦涉及跨執行緒就很容易出錯,回想下訊號槽的作用就是用來物件與物件之間通訊的,難免會跨執行緒,建議在使用自定義型...