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

网站建设的布局陕西省高速建设集团网站

网站建设的布局,陕西省高速建设集团网站,建站哪家好就要用兴田德润,wordpress一键优化// 我们假设有一个QLabel 用来显示某某信息#xff0c;但是信息有时候过长#xff0c;高度超过了QLabel的高度 // 这时候最好的方法是让其滚动#xff0c;那么我们就来实现以下上下滚动。 // 要用到的QT 事件 void showEvent(QShowEvent *); void paintEvent(QPaintEvent *… // 我们假设有一个QLabel 用来显示某某信息但是信息有时候过长高度超过了QLabel的高度 // 这时候最好的方法是让其滚动那么我们就来实现以下上下滚动。 // 要用到的QT 事件  void showEvent(QShowEvent *); void paintEvent(QPaintEvent *); void timerEvent(QTimerEvent *); void hideEvent(QHideEvent *); // paintEvent 这个事件是重绘事件 // timerEvent 既然是滚动肯定有个定时器这是定时器事件 // showEvent  显示事件 例如 label-show() 时候触发 // hideEvent  隐藏事件 例如 label-hide() 时候触发 // 下面就附上代码进行详细说明 这里我们定义 VScrollLabel 类 ------------------------------ Vscrolllabel.h------------------------- #ifndef VSCROLLLABEL_H #define VSCROLLLABEL_H #include QLabel class VScrollLabel : public QLabel    // 继承 QLabel类 { Q_OBJECT public: explicit VScrollLabel(QWidget *parent 0, Qt::WindowFlags f0); virtual ~VScrollLabel(){} public slots: void setText(const QString ); protected: void showEvent(QShowEvent *); void paintEvent(QPaintEvent *); void timerEvent(QTimerEvent *); void hideEvent(QHideEvent *); private slots: void metrics(); void startScroll(); signals: void currentTextChanged(); private: int getHeight(); private: int offset; int timerID; int textHeight; }; #endif // VSCROLLLABEL_H ------------------------------ Vscrolllabel.cpp------------------------- #include vscrolllabel.h #include QPainter #include QTimerEvent #include QTimer VScrollLabel::VScrollLabel(QWidget *parent, Qt::WindowFlags f) : QLabel(parent,f) { offset timerID textHeight 0; connect(this, SIGNAL(currentTextChanged()), SLOT(metrics())); } void VScrollLabel::setText(const QString curText) { if (text() ! curText) { QLabel::setText(curText); emit currentTextChanged(); } } // 开始启动定时器 设为 50 void VScrollLabel::startScroll() { timerID startTimer(50); } void VScrollLabel::metrics() { offset 0; // getHeight QLabel高度是为了 一段过长的文字显示完后再重新开始滚动显示 // 不然的话第一行会紧接着末尾显示出来。 textHeight getHeight() height() ;    QTimer::singleShot(500, this, SLOT(startScroll())); this-update(); } // 这里是重点我们得到的一段信息有没有换行符号要自动换行 // 这就要得到字体的高度和宽度来处理这一段文字处理完后调用 // setText() 设置到Qlabel 上面去。 int VScrollLabel::getHeight() { #define MARGIN  5 char newMsg[1024] {0}; char *message text().toLatin1().data(); int len strlen(message); char mss[len]; memcpy(mss,text().toLatin1().data(),len); int i; int row 1; int line_width 0; int font_width 0; int max_width 0; int j0; QFontMetrics fm fontMetrics(); int  h 18;    // 这里指定我们想要的字体高度 printf(len   %d\n,len); for (i0; ilen; i) { font_width fm.width(mss[i]);  if (mss[i] \n) {       // line feed line_width 0; newMsg[j] mss[i]; row; continue; } if ((line_widthfont_width) width()) { max_width line_width; newMsg[j] \n; line_width 0; row; } line_width font_width; newMsg[j] mss[i]; //printf(line_width %d\n,line_width); if (line_width max_width) max_width line_width; if(j sizeof(newMsg)-1) break; } printf(row %d\n,row); // 上面经过处理得到结果查看下有多少行。 // 设置到QLabel 上去 setText(newMsg);         // 返回 行*字体高度 这里我们加了10 的预留空间。 return row*h(MARGIN1); } // 显示我们就启动定时器 void VScrollLabel::showEvent(QShowEvent *) { metrics(); } void VScrollLabel::paintEvent(QPaintEvent *event) { QPainter painter(this); if (textHeight 1) return; int y -offset; while (y height()) { painter.drawText(0, y, width(), textHeight, Qt::AlignLeft | Qt::AlignVCenter, text()); y textHeight; } } void VScrollLabel::timerEvent(QTimerEvent *event) { if (event-timerId() timerID) { offset; if (offset textHeight)  offset 0; scroll(0, -1);    // X 轴不变Y 轴 向上偏移 1 } else { QWidget::timerEvent(event); } } // 隐藏我们就停止掉 定时器 void VScrollLabel::hideEvent(QHideEvent *) { offset 0; if (timerID) killTimer(timerID); }
http://www.dnsts.com.cn/news/104217.html

相关文章:

  • 手机网站页面尺寸大小网站的建设流程是什么
  • 网站建设都包含什么步骤网站开发人员 kpi指标
  • 做网站排版网站按域名跳转不同的页面
  • 扁平化 公司网站网站后端开发流程
  • wordpress企业仿站视频教程wordpress代码解析
  • wordpress无法访问站点公众号关注推广
  • 云南澄江县建设局网站wordpress搭建电子商务
  • 网站排名优化提升快速如何做网页公证
  • 做企业网站哪个平台好金坛做网站
  • 南康家具网站建设钢笔工具网站
  • 网站模板可以自己做吗淄博网站制作首选专家
  • 本溪 网站建设 做网站外贸网站源码多语言
  • 关键词优化技巧有哪些wordpress建站seo好做吗
  • python 如何做网站商业十大网站
  • 免费建设网站和域名wordpress中文是什意思
  • 建设网站要多久到账常平网站
  • 网站运营适合什么样的人做企业宣传片制作拍摄电话
  • WordPress node企业为什么做网站优化推广
  • 网址查询站长工具做网站常用图标
  • 小说网站80电子书怎么做换服务器wordpress升级
  • 顺德网站建设公司有哪些郑州模板网站制作
  • 公司网站优化哪家好网址广告
  • 江门市网站建设帮别人做视频剪辑的网站
  • 网站网店建设wordpress404错误
  • 汉字叔叔花了多少钱做网站赶集招聘网
  • 免费建站系统wordpress电子商务论文3000字
  • 郑州响应式网站建设广告公司网站建设方案
  • 广州在建火车站在哪里网络推广培训学校
  • 手机网站 app网站开发外包项目网站
  • 泉州专门做网站网站推广排名怎么做