ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:24.75KB ,
资源ID:3870511      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3870511.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(QT 滑动按钮的实现.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

QT 滑动按钮的实现.docx

1、QT 滑动按钮的实现方法一:mouselabel.h #ifndef MOUSELABEL_H#define MOUSELABEL_H#include myslider.hclass MySliderMenu; /为做设置界面里一个漂亮滑块而写的类。class mouseLabel : public QLabel friend class MySliderMenu; Q_OBJECTprivate: QString ImageBgPath; QString ImageSwPath; MySliderMenu *FocusLabel; bool releaseFlag;public: mouse

2、Label(QWidget *parent,MySliderMenu *focusLabel); void mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *ev); void setTwoImage(QString ImageBg,QString ImageSw); #endif / MOUSELABEL_H- myslider.h class mouseLabel;/为做设置界面里一个漂亮滑块而写的类。class MySlider

3、Menu :public QLabel friend class mouseLabel; Q_OBJECTprivate: QPixmap PixmapBg; QPixmap PixmapSw; QLabel *ImageBgLabel; QLabel *ImageSwLabel; / QLabel *TextBgLabel; mouseLabel *TextSwLabel; int SliderId; int xPos; int yPos; int State;public: MySliderMenu(QWidget * parent,int x, int y, QString imageB

4、gPath, QString imageSwPath,int nSliderID); void setPosition(int x,int y); void moveImageSw(int pos); void moveImageSwLittle(int pos); void mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *ev); int getSliderID(); int getState();/extern MySlider

5、Menu MySlider; #define MENU_ON 1#define MENU_OFF 2 #endif / MYSLIDER_H-mouselabel.cpp #include mouselabel.h#include myslider.h mouseLabel:mouseLabel(QWidget *parent,MySliderMenu *focusLabel):QLabel(parent) FocusLabel = focusLabel; releaseFlag = true; void mouseLabel:mousePressEvent(QMouseEvent *e)vo

6、id mouseLabel:mouseReleaseEvent(QMouseEvent *e) releaseFlag = true; if(FocusLabel-getState() = MENU_OFF) FocusLabel-moveImageSw(MENU_OFF); else FocusLabel-moveImageSw(MENU_ON); void mouseLabel:mouseMoveEvent(QMouseEvent *ev) static QPoint FirstPoint,LastPoint; if(releaseFlag) FirstPoint = QCursor:po

7、s(); releaseFlag = false; LastPoint = QCursor:pos();/获取当前光标的位置 if(LastPoint.x() - FirstPoint.x() 10) if(FocusLabel-getState() = MENU_ON) FocusLabel-moveImageSwLittle(MENU_OFF); if(FirstPoint.x() - LastPoint.x() 10) if(FocusLabel-getState() = MENU_OFF) FocusLabel-moveImageSwLittle(MENU_ON); if(LastPo

8、int.x() - FirstPoint.x() 80) if(FocusLabel-getState() = MENU_ON) FocusLabel-moveImageSw(MENU_OFF); if(FirstPoint.x() - LastPoint.x() 80) if(FocusLabel-getState() = MENU_OFF) FocusLabel-moveImageSw(MENU_ON); / printf(x:%d,Y:%dn,LastPoint.x(),LastPoint.y();-myslider.cpp#include myslider.h#include #inc

9、lude main.h#include language.h#include mouselabel.h /为做设置界面里一个漂亮滑块开关而写的类。MySliderMenu:MySliderMenu(QWidget * parent,int x, int y, QString imageBgPath, QString imageSwPath,int nSliderID) :QLabel(parent) PixmapBg.load(imageBgPath); PixmapSw.load(imageSwPath); ImageBgLabel = new QLabel(parent); this-ra

10、ise(); ImageSwLabel = new QLabel(parent); /TextBgLabel = new QLabel(parent); TextSwLabel = new mouseLabel(parent,this); ImageBgLabel-setPixmap(PixmapBg); ImageSwLabel-setPixmap(PixmapSw); ImageBgLabel-setGeometry(x,y,PixmapBg.rect().width(),PixmapBg.rect().height(); QPalette pal; pal.setColor(QPalet

11、te:WindowText,Qt:white); QString str1= ,str2= ; str1 += Str_On; str2 += Str_Off; this-setText(QObject:tr(str1+str2).toLocal8Bit().data(); /this-installEventFilter(this); this-setPalette(pal); this-setGeometry(x,y,PixmapBg.rect().width(),PixmapBg.rect().height(); ImageSwLabel-setGeometry(x-1,y-1,Pixm

12、apSw.rect().width(),PixmapSw.rect().height(); TextSwLabel-setGeometry(x-1,y-1,PixmapSw.rect().width(),PixmapSw.rect().height(); TextSwLabel-setText(QObject:tr(Str_On); TextSwLabel-setAlignment(Qt:AlignCenter); TextSwLabel-setPalette(pal); / setMouseTracking(true); /这是激活整个窗体的鼠标追踪 /gpFrameMenu4-setMou

13、seTracking(true); /这是激活整个窗体的鼠标追踪 /this-installEventFilter(this); xPos = x; yPos = y; State = MENU_ON; SliderId = nSliderID;void MySliderMenu:setPosition(int x,int y) this-setGeometry(x,y,PixmapBg.rect().width(),PixmapBg.rect().height(); ImageSwLabel-setGeometry(x-1,y-1,PixmapSw.rect().width(),Pixmap

14、Sw.rect().height();void MySliderMenu:moveImageSw(int pos) if(pos = MENU_ON) ImageSwLabel-setGeometry(xPos-1,yPos-1,PixmapSw.rect().width(),PixmapSw.rect().height(); TextSwLabel-setText(QObject:tr(Str_On); TextSwLabel-setGeometry(xPos-1,yPos-1,PixmapSw.rect().width(),PixmapSw.rect().height(); State =

15、 MENU_ON; else if(pos =MENU_OFF) ImageSwLabel-setGeometry(xPos+PixmapBg.rect().width()/2,yPos-1,PixmapSw.rect().width(),PixmapSw.rect().height(); TextSwLabel-setText(QObject:tr(Str_Off); TextSwLabel-setGeometry(xPos+PixmapBg.rect().width()/2,yPos-1,PixmapSw.rect().width(),PixmapSw.rect().height(); S

16、tate =MENU_OFF ; void MySliderMenu:moveImageSwLittle(int pos) if(pos = MENU_ON) ImageSwLabel-setGeometry(xPos+PixmapBg.rect().width()/2-10,yPos-1,PixmapSw.rect().width(),PixmapSw.rect().height(); TextSwLabel-setText(QObject:tr(Str_Off); TextSwLabel-setGeometry(xPos+PixmapBg.rect().width()/2-10,yPos-

17、1,PixmapSw.rect().width(),PixmapSw.rect().height(); else if(pos = MENU_OFF) ImageSwLabel-setGeometry(xPos+9,yPos-1,PixmapSw.rect().width(),PixmapSw.rect().height(); TextSwLabel-setText(QObject:tr(Str_On); TextSwLabel-setGeometry(xPos+9,yPos-1,PixmapSw.rect().width(),PixmapSw.rect().height(); int MyS

18、liderMenu:getSliderID() return SliderId;int MySliderMenu:getState() return State;void MySliderMenu:mousePressEvent(QMouseEvent *e) if(State = MENU_OFF) moveImageSw(MENU_ON); else moveImageSw(MENU_OFF); / printf(press n);void MySliderMenu:mouseReleaseEvent(QMouseEvent *e) /* if(State = 2) moveImageSw

19、(1); else moveImageSw(2); */ / printf(release n);void MySliderMenu:mouseMoveEvent(QMouseEvent *ev) /* if(State = 2) moveImageSw(1); else moveImageSw(2); */ / printf(mouve n); 使用的时候 nX = 0;/位置坐标 nY = 0; defImagePath = slider_bg.png;/背景及开关图片 actImagePath = slider.png; MySliderMenu *pMySlider = new MyS

20、liderMenu(pFrameMenu,nX,nY,defImagePath,actImagePath,0);其中pFrameMenu 是父窗口 效果: 方法二:#ifndef SWITCHMENU_H#define SWITCHMENU_H #include class SwitchMenu : public QWidget Q_OBJECTpublic: explicit SwitchMenu(QWidget *parent = 0); protected: virtual void paintEvent(QPaintEvent *); virtual void mousePressEv

21、ent(QMouseEvent *); virtual void mouseReleaseEvent(QMouseEvent *); signals: public slots: public: void initialize(const QString&, const QString&); private: QPixmap m_pixmapBk; QPixmap m_pixmapFore; bool m_bOn; bool m_bLBtnDown; #endif / SWITCHMENU_H #include switchmenu.h #include #include SwitchMenu

22、:SwitchMenu(QWidget *parent) : QWidget(parent) setWindowFlags(Qt:FramelessWindowHint); m_bOn = false; m_bLBtnDown = false; void SwitchMenu:paintEvent(QPaintEvent *) QPainter painter(this); painter.drawPixmap(QPoint(0,0), m_pixmapBk); QPoint ptFore; if (m_bOn) ptFore = rect().topLeft(); else ptFore =

23、 QPoint(this-width() - m_pixmapFore.width(), this-rect().top(); painter.drawPixmap(ptFore, m_pixmapFore); QRect rcOn; rcOn.setTopLeft(rect().topLeft(); rcOn.setBottomRight(QPoint(m_pixmapFore.width(), m_pixmapFore.height(); painter.drawText(rcOn, Qt:AlignCenter, ON); QRect rcOff; rcOff.setTopLeft(QP

24、oint(rect().width() - m_pixmapFore.width(), rect().top(); rcOff.setBottomRight(rect().bottomRight(); painter.drawText(rcOff, Qt:AlignCenter, Off); void SwitchMenu:mousePressEvent(QMouseEvent *) m_bLBtnDown = true; void SwitchMenu:mouseReleaseEvent(QMouseEvent *e) if (m_bLBtnDown) m_bOn = !m_bOn; m_b

25、LBtnDown = false; update(); void SwitchMenu:initialize(const QString& strImageBk, const QString& strImageFore) m_pixmapBk.load(strImageBk); m_pixmapFore.load(strImageFore); int nWidth = m_pixmapBk.width(); int nHeight = m_pixmapBk.height(); setGeometry(0, 0, m_pixmapBk.width(), m_pixmapBk.height(); 使用方法: SwitchMenu switchMenu; switchMenu.initialize(:/res/switchMenu_bk, :/res/switchMenu_fore); switchMenu.show(); 这样就可以了。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1