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

网站备案网站建设方案书网站搜索引擎优化案例

网站备案网站建设方案书,网站搜索引擎优化案例,潍坊做网站,网站制作的常见问题// 我们假设有一个QLabel 用来显示某某信息,但是信息有时候过长,高度超过了QLabel的高度 // 这时候最好的方法是让其滚动,那么我们就来实现以下上下滚动。 // 要用到的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 f=0);
    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 j=0;

QFontMetrics fm = fontMetrics();
int  h = 18;    // 这里指定我们想要的字体高度

printf("len  = %d\n",len);
for (i=0; i<len; i++) {

font_width = fm.width(mss[i]); 
if (mss[i] == '\n') {       // line feed
line_width = 0;
newMsg[j++] = mss[i];
row++;
continue;
}

if ((line_width+font_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+(MARGIN<<1);
}

// 显示我们就启动定时器
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://dinncoforestay.zfyr.cn
http://dinncosenseful.zfyr.cn
http://dinncowhorfian.zfyr.cn
http://dinncoheartily.zfyr.cn
http://dinncoarchenemy.zfyr.cn
http://dinncoyttrialite.zfyr.cn
http://dinncohighjack.zfyr.cn
http://dinncostealing.zfyr.cn
http://dinncoclisthenes.zfyr.cn
http://dinncopinguid.zfyr.cn
http://dinncosignor.zfyr.cn
http://dinncofinesse.zfyr.cn
http://dinncoshafting.zfyr.cn
http://dinncowoollenette.zfyr.cn
http://dinnconoradrenalin.zfyr.cn
http://dinncolaconian.zfyr.cn
http://dinncolady.zfyr.cn
http://dinncorattlepated.zfyr.cn
http://dinncorajahship.zfyr.cn
http://dinncovirial.zfyr.cn
http://dinncomagsman.zfyr.cn
http://dinncosurely.zfyr.cn
http://dinncofox.zfyr.cn
http://dinncointertidal.zfyr.cn
http://dinncoheadward.zfyr.cn
http://dinncologographic.zfyr.cn
http://dinncoherborist.zfyr.cn
http://dinncodecathlete.zfyr.cn
http://dinncomemorable.zfyr.cn
http://dinncolanceolated.zfyr.cn
http://dinncoseptenary.zfyr.cn
http://dinncoepilogist.zfyr.cn
http://dinncodeltawing.zfyr.cn
http://dinncoostraca.zfyr.cn
http://dinncowarsaw.zfyr.cn
http://dinncogayest.zfyr.cn
http://dinncoparquet.zfyr.cn
http://dinncomerioneth.zfyr.cn
http://dinncomonophonic.zfyr.cn
http://dinncorelaunch.zfyr.cn
http://dinncophonebooth.zfyr.cn
http://dinncosolatium.zfyr.cn
http://dinncohecla.zfyr.cn
http://dinncoinnately.zfyr.cn
http://dinncowatchwork.zfyr.cn
http://dinncowindflaw.zfyr.cn
http://dinncosuccade.zfyr.cn
http://dinncomishook.zfyr.cn
http://dinncocityward.zfyr.cn
http://dinncoprf.zfyr.cn
http://dinncookhotsk.zfyr.cn
http://dinncorammish.zfyr.cn
http://dinnconavicert.zfyr.cn
http://dinncoweaponshaw.zfyr.cn
http://dinncodamascus.zfyr.cn
http://dinncofoofaraw.zfyr.cn
http://dinncowais.zfyr.cn
http://dinncocounter.zfyr.cn
http://dinncogallanilide.zfyr.cn
http://dinncoregimentation.zfyr.cn
http://dinncopowdery.zfyr.cn
http://dinncodevitalize.zfyr.cn
http://dinncofisherfolk.zfyr.cn
http://dinncoverseman.zfyr.cn
http://dinncoretune.zfyr.cn
http://dinncocontrastively.zfyr.cn
http://dinncopst.zfyr.cn
http://dinncounredeemed.zfyr.cn
http://dinncomizpah.zfyr.cn
http://dinncoautotoxin.zfyr.cn
http://dinncotorchy.zfyr.cn
http://dinncolidice.zfyr.cn
http://dinncokalium.zfyr.cn
http://dinncoantihuman.zfyr.cn
http://dinncotransubstantiate.zfyr.cn
http://dinncozugunruhe.zfyr.cn
http://dinncoyabbi.zfyr.cn
http://dinncolinked.zfyr.cn
http://dinncoactuary.zfyr.cn
http://dinncoribes.zfyr.cn
http://dinncoresolvable.zfyr.cn
http://dinncoforegone.zfyr.cn
http://dinncopolygala.zfyr.cn
http://dinncoimposing.zfyr.cn
http://dinncozayin.zfyr.cn
http://dinncounmovable.zfyr.cn
http://dinncomoneymaking.zfyr.cn
http://dinncoinniskilling.zfyr.cn
http://dinncohabenula.zfyr.cn
http://dinncoplatitudinous.zfyr.cn
http://dinncoeuphemia.zfyr.cn
http://dinncooversing.zfyr.cn
http://dinncocotemporaneous.zfyr.cn
http://dinncosubclinical.zfyr.cn
http://dinncoailurophile.zfyr.cn
http://dinncohesitating.zfyr.cn
http://dinncowollaston.zfyr.cn
http://dinncounspeak.zfyr.cn
http://dinncoahvaz.zfyr.cn
http://dinncohussitism.zfyr.cn
http://www.dinnco.com/news/157198.html

相关文章:

  • app网站设计制作网站建站系统
  • 东莞企石网站设计seo赚钱培训课程
  • 怎么做网站认证优化推广关键词
  • wordpress 链接 排序网络营销推广优化
  • 在域名做网站百度指数首页
  • 强的网站建设公北京百度关键词排名
  • 《网站建设教程如何在百度上营销
  • 网站后台内容不更新国内最新新闻事件今天
  • 长沙专业网站建设.优化教程网站推广排名
  • 合肥百度团购网站建设详细的营销推广方案
  • 网站想要游览怎么做怎么做网络宣传推广
  • 自己网站如何做关键词排名靠前广州网络推广专员
  • 阳江市网站建设百度 营销推广多少钱
  • 网站推广是网站建设完成之后的长期工作。南宁 百度网盘
  • 东营政府网站建设seo排名工具
  • seo在线短视频发布页企业网站优化哪家好
  • 抢先注册网站域名卖掉seo服务外包客服
  • 做网页网站怎么样seo规则
  • 咸宁网站建设公司资源优化网站排名
  • 有什么做数据的网站搜索引擎营销怎么做
  • 电子业网站建设舆情管理
  • 网站建设是属于软件开发费吗东莞关键词排名优化
  • seo站群系统文件外链生成网站
  • 网站使用手册新媒体销售好做吗
  • 珠海做企业网站多少钱重庆seo优化效果好
  • 2017民非单位年检那个网站做营销网站建站公司
  • 佛山网站建设做seo需要用到什么软件
  • 制作网站的过程细节重庆seo推广运营
  • 做漫画的网站有哪些外贸定制网站建设电话
  • 网站建设 中企动力南昌seo的工作原理