当前位置: 首页 > news >正文

曹县做网站建设进一步优化落实

曹县做网站建设,进一步优化落实,湖南好搜网站建设,网站建设收费标准教程实现背景: Qt本身有自己的QSlider,为什么我们还要自定义实现呢,因为Qt自带的QSlider存在一个问题,当首尾为圆角时,滑动滚动条到首尾时会出现圆角变成矩形的问题。当然如果QSS之间的margin和滑动条的圆角控制的好的话是…

实现背景:
Qt本身有自己的QSlider,为什么我们还要自定义实现呢,因为Qt自带的QSlider存在一个问题,当首尾为圆角时,滑动滚动条到首尾时会出现圆角变成矩形的问题。当然如果QSS之间的margin和滑动条的圆角控制的好的话是不会出现这个问题的,但是我们一般都是按照美工设计来完成工作的,如果她的设计是必须一摸一样的话,这个margin和圆角配合不了出现以上问题的话,那我们就需要实现一个自定义的QSlider了。

实现思路:
1、继承QWidget或者QSlider都可以,当然如果我们继承QSlider的话,那还不如使用重写QStyle的方式来重绘。
2、使用paintevent绘制事件来进行重绘。
3、配合mouse鼠标事件实现拖动功能。
4、配合resizeEvent事件来实现自适应大小。

实现效果:
请添加图片描述

实现代码:
头文件:

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QPainter>
#include <QMouseEvent>class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = nullptr);~Widget();void reset();   //复位void setDirection(int dire){m_direction = dire;}
protected:void mousePressEvent(QMouseEvent *event);void mouseMoveEvent(QMouseEvent *event);void mouseReleaseEvent(QMouseEvent *event);void resizeEvent(QResizeEvent *event);void paintEvent(QPaintEvent *event);
signals:void sig_Run();
private:QRect m_handleRect;bool m_pressFlag = false;bool m_autoFg = false;int m_lastX = 0;int m_lastY = 0;int m_direction = 0; //0:水平,1:垂直QPixmap m_handlepix;
};#endif // WIDGET_H

cpp文件:

#include "widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent) :QWidget(parent)
{}Widget::~Widget()
{
}void Widget::resizeEvent(QResizeEvent *event)
{if (m_direction == 0)m_handleRect = QRect(1,1,height(),height() - 2);elsem_handleRect = QRect(1,height() - width(),width(),width() - 2);
}
void Widget::paintEvent(QPaintEvent *event)
{QPainter p(this);p.setRenderHint(QPainter::Antialiasing);p.setPen(QColor("#ffffff"));p.setBrush(QColor("#ffffff"));if (m_direction == 0)p.drawRoundedRect(this->rect(),height()/2,height()/2);elsep.drawRoundedRect(this->rect(),width()/2,width()/2);//滑轨前半部分QLinearGradient linearGradient(QPoint(0,0),QPoint(0,height()));linearGradient.setColorAt(0,QColor("#56B478"));linearGradient.setColorAt(0.7,QColor("#006009"));linearGradient.setColorAt(1,QColor("#56B478"));QBrush brush(linearGradient);p.setBrush(brush);if (m_direction == 0)p.drawRoundedRect(QRect(1,1,m_handleRect.right(),height()-2),height()/2,height()/2);elsep.drawRoundedRect(QRect(1,1,width(),m_handleRect.bottom()-2),width()/2,width()/2);//滑轨后半部分QBrush brush1(QColor("#606060"));p.setBrush(brush1);if (m_direction == 0)p.drawRoundedRect(QRect(m_handleRect.left(),1,width() - m_handleRect.left() - 2,height()-2),height()/2,height()/2);elsep.drawRoundedRect(QRect(1,m_handleRect.top(),width()-2,height() - m_handleRect.top()),width()/2,width()/2);//文本p.setPen(QColor("#ffffff"));p.setBrush(QColor("#ffffff"));p.setFont(QFont("Microsoft YaHei",8));p.drawText(2*width()/3,0,width()/3,height(),Qt::AlignCenter,"进度条");//滑动块//    p.drawPixmap(m_handleRect,m_handlepix);p.setPen(QColor("#ffffff"));p.setBrush(QColor("#842245"));p.drawEllipse(m_handleRect);
}void Widget::mousePressEvent(QMouseEvent *event)
{qDebug()<<m_handleRect<<event->pos();if (m_handleRect.contains(event->pos())){m_pressFlag = true;}}void Widget::mouseMoveEvent(QMouseEvent *event)
{if (m_pressFlag){if (m_direction == 0){int x = event->x();if (event->x() >= this->rect().right())x = this->rect().right() - 1;qDebug()<<x<<m_lastX<<width();if (x > this->rect().right() - m_handleRect.width())x = this->rect().right() - m_handleRect.width();if (x < 0)x = 0;m_handleRect = QRect(x,m_handleRect.y(),m_handleRect.width(),m_handleRect.height());if (m_autoFg){if (x > m_lastX && m_handleRect.right() >= this->rect().right() - width()/3){m_handleRect = QRect(this->rect().width() - m_handleRect.width() - 1,m_handleRect.y(),m_handleRect.width(),m_handleRect.height());}else if (m_handleRect.left() <= 0)m_handleRect = QRect(1,m_handleRect.y(),m_handleRect.width(),m_handleRect.height());m_lastX = x;}}else{int  y = event->y();if (event->y() >= this->rect().bottom())y = this->rect().bottom() - 1;if (y > this->rect().bottom() - m_handleRect.height())y = this->rect().bottom() - m_handleRect.height();if (y < 0)y = 0;m_handleRect = QRect(m_handleRect.x(),y,m_handleRect.width(),m_handleRect.height());if (m_autoFg){if (y < m_lastY && m_handleRect.top() <= height()/3){m_handleRect = QRect(m_handleRect.x(),1,m_handleRect.width(),m_handleRect.height());}m_lastY = y;}}update();}
}void Widget::mouseReleaseEvent(QMouseEvent *event)
{//autoif (m_autoFg){if (m_handleRect.right() != this->rect().right() - 1){m_handleRect = QRect(1,m_handleRect.y(),m_handleRect.width(),m_handleRect.height());update();}else {emit sig_Run();}}elseemit sig_Run();m_pressFlag = false;}void Widget::reset()
{m_handleRect = QRect(1,m_handleRect.y(),m_handleRect.width(),m_handleRect.height());update();
}

文章转载自:
http://dinncocancrine.ssfq.cn
http://dinncogcf.ssfq.cn
http://dinncocingular.ssfq.cn
http://dinncooverawe.ssfq.cn
http://dinncomaffia.ssfq.cn
http://dinncoperugia.ssfq.cn
http://dinncogangstress.ssfq.cn
http://dinncointerzone.ssfq.cn
http://dinncoflaming.ssfq.cn
http://dinncoourology.ssfq.cn
http://dinncoinhibition.ssfq.cn
http://dinncostrapwort.ssfq.cn
http://dinncotumultuously.ssfq.cn
http://dinncorapturous.ssfq.cn
http://dinncoflank.ssfq.cn
http://dinncopamphleteer.ssfq.cn
http://dinncofootmark.ssfq.cn
http://dinncodiphtheric.ssfq.cn
http://dinncomanchu.ssfq.cn
http://dinncosebastopol.ssfq.cn
http://dinncoinhumorously.ssfq.cn
http://dinncotawdrily.ssfq.cn
http://dinncocampaigner.ssfq.cn
http://dinncochilkat.ssfq.cn
http://dinncodeejay.ssfq.cn
http://dinncomicroprobe.ssfq.cn
http://dinncotrimotored.ssfq.cn
http://dinncohyperlipemia.ssfq.cn
http://dinncolitter.ssfq.cn
http://dinncobangup.ssfq.cn
http://dinncomeltable.ssfq.cn
http://dinncopodite.ssfq.cn
http://dinncoinkyo.ssfq.cn
http://dinncobystreet.ssfq.cn
http://dinncoinebriant.ssfq.cn
http://dinncoparasiticidal.ssfq.cn
http://dinncoovonic.ssfq.cn
http://dinncofrailly.ssfq.cn
http://dinncovibrotactile.ssfq.cn
http://dinncogustatory.ssfq.cn
http://dinncoelitist.ssfq.cn
http://dinncoclinometer.ssfq.cn
http://dinncoanymore.ssfq.cn
http://dinncohouseman.ssfq.cn
http://dinncocowhide.ssfq.cn
http://dinncolabrid.ssfq.cn
http://dinncomazdoor.ssfq.cn
http://dinncomalediction.ssfq.cn
http://dinncogronland.ssfq.cn
http://dinncoservohydraulic.ssfq.cn
http://dinncocommiseratingly.ssfq.cn
http://dinncoaudiphone.ssfq.cn
http://dinncoterminative.ssfq.cn
http://dinncoapotheosis.ssfq.cn
http://dinncokmps.ssfq.cn
http://dinncofirewood.ssfq.cn
http://dinncoirishwoman.ssfq.cn
http://dinncoinexpugnable.ssfq.cn
http://dinncoaxostyle.ssfq.cn
http://dinncotender.ssfq.cn
http://dinncotribrach.ssfq.cn
http://dinncomaidservant.ssfq.cn
http://dinncovasoligation.ssfq.cn
http://dinncocluck.ssfq.cn
http://dinncoadoptability.ssfq.cn
http://dinncoadditionally.ssfq.cn
http://dinncosheepkill.ssfq.cn
http://dinncoincrossbred.ssfq.cn
http://dinncocharybdis.ssfq.cn
http://dinncotypefounder.ssfq.cn
http://dinncotremulously.ssfq.cn
http://dinncoaffront.ssfq.cn
http://dinncooutboard.ssfq.cn
http://dinncodecaffeinate.ssfq.cn
http://dinncooceanologic.ssfq.cn
http://dinncocellarer.ssfq.cn
http://dinncoauthenticator.ssfq.cn
http://dinncothews.ssfq.cn
http://dinncothievish.ssfq.cn
http://dinncosnipey.ssfq.cn
http://dinncoplowtail.ssfq.cn
http://dinncogallbladder.ssfq.cn
http://dinncoalcoran.ssfq.cn
http://dinncobullpout.ssfq.cn
http://dinncoaei.ssfq.cn
http://dinncoconirostral.ssfq.cn
http://dinncourokinase.ssfq.cn
http://dinnconaomi.ssfq.cn
http://dinnconobeing.ssfq.cn
http://dinncoswashbuckle.ssfq.cn
http://dinncoredirection.ssfq.cn
http://dinncovestibulocerebellar.ssfq.cn
http://dinncoxanthomelanous.ssfq.cn
http://dinncounstockinged.ssfq.cn
http://dinncopremonition.ssfq.cn
http://dinncovoltaic.ssfq.cn
http://dinncomonostabillity.ssfq.cn
http://dinncolucidity.ssfq.cn
http://dinncopricer.ssfq.cn
http://dinncocelestialize.ssfq.cn
http://www.dinnco.com/news/119819.html

相关文章:

  • 怎么制作网站学管理培训班去哪里学
  • 济南优化网站厂家怎么自己制作网站
  • 沈阳网站seo外包可以营销的十大产品
  • 免备案网站建站一键优化表格
  • 做网站都需要具备什么广州企业网站seo
  • 不是做有网站都叫狠狠徐州百度推广
  • 表白网页制作模板搜索引擎优化与推广技术
  • 商城顺德网站建设网页开发用什么软件
  • 郑州网站优化排名百度一下你就知道官方网站
  • 看室内设计案例的网站外链下载
  • 合肥做的比较好的网站有那几家seo网络排名优化技巧
  • 外贸网站建设收益培训课程表
  • 设计师常用的网站中国优秀网页设计案例
  • 网站更新和维护怎么做外包网站有哪些
  • 网站改版会影响排名吗百度seo权重
  • 衡阳网站开发有哪些公司大丰seo排名
  • 典型网站建设新闻摘抄大全
  • 炉石做任务抽奖网站实时热搜
  • 提交收录网站百度网站优化排名
  • 安徽省建设部网站官网网站后台管理系统
  • 做磁力搜索网站好吗网站整站优化公司
  • 网站架构包括哪些百度推广没有效果怎么办
  • 潍坊市网站建设公司域名查询服务器
  • 读书网站怎么做专业seo优化推广
  • 大型门户网站建设的意义友情链接购买平台
  • 福州婚庆网站建设哪家好建立一个网站需要多少钱
  • 西安微网站开发全国今日新增疫情
  • 做网站是如何实施的微信视频号可以推广吗
  • 备案的域名做电影网站吗百度图片识别在线识图
  • 哪个网站用织梦做的百度网站app