在登陸介面中,經常用到滑動驗證的方式,來確保賬號安全
效果圖:
樣式1
樣式2
標頭檔案
#ifndef qwhsliderverification_h
#define qwhsliderverification_h
#include #include #include #include #include #include class qwhsliderverification : public qwidget
; explicit qwhsliderverification(qwidget *parent = nullptr);
~qwhsliderverification();
protected:
void paintevent(qpaintevent *);
void mousepressevent(qmouseevent *event);
void mousemoveevent(qmouseevent *event);
void mousereleaseevent(qmouseevent *event);
void resizeevent(qresizeevent *event);
void drawnormalslider(qpainter *painter);
void drawpictureslider(qpainter *painter);
private:
qpainterpath pixpath(const qrectf pixrect);
signals:
void passverification(bool verification);
public slots:
private:
int m_sliderx; //滑塊左側位置
int m_sliderwidth; //滑塊寬度
int m_sliderheight; //滑塊高度
float m_sliderwratioh; //滑塊寬度與高度比值,值為0+,推薦1.2
int m_pointleftwidth; //滑鼠按下點距滑塊左側距離
bool m_pressedinslider; //滑鼠是否按下且在滑塊中
bool m_passverification; //是否通過驗證
qcolor m_sliderbordercolor; //邊框顏色
qcolor m_sliderbgcolor; //滑動條背景顏色
qcolor m_slidertiptextcolor; //滑動條提示文字顏色
qcolor m_sliderblockmovecolor; //滑塊劃過區域顏色
qcolor m_sliderblockbgcolor; //滑塊背景色
qcolor m_sliderblocktextcolor; //滑塊文字顏色
qtime m_presstime; //滑塊按下時間
qtime m_releasetime; //滑塊釋放時間
slidertype m_slidertype; //滑塊驗證樣式
};#endif // qwhsliderverification_h
核心**
void qwhsliderverification::paintevent(qpaintevent *)
else if (m_slidertype == slidertype_picture) }
void qwhsliderverification::drawnormalslider(qpainter *painter)
//驗證通過後
else if (m_passverification)
painter->restore();
}
Qt自定義控制項 繪製滑動條
主要 展示 標頭檔案 ifndef myslider h define myslider h include include include include include class myslider public qwidget q object public explicit myslider...
QT文字繪製
1 基本繪製 qpainter painter this 這個this要斟酌下 painter.drawtext 100,100,yafeilinux 2 中級繪製 qpainter painter this qrectf ff 100,100,300,200 設定乙個矩形 painter.draw...
Qt繪製文字
1 基本繪製 qpainter painter this 這個this要斟酌下 painter.drawtext 100,100,yafeilinux 2 中級繪製 qpainter painter this qrectf ff 100,100,300,200 設定乙個矩形 painter.draw...