社区
Qt
帖子详情
Qpainter drawline画线
zhz604483686
2012-07-23 04:32:52
在一个label上水平方向均匀画了15条线,就显示出11条,有谁知道是怎么回事吗?
...全文
783
5
打赏
收藏
Qpainter drawline画线
在一个label上水平方向均匀画了15条线,就显示出11条,有谁知道是怎么回事吗?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zhz604483686
2012-07-24
打赏
举报
回复
没有啊,是中间的线没显示,两端的都有
zhz604483686
2012-07-24
打赏
举报
回复
代码如下,请大侠们指点啊
#include<QtGui>
#include"mylabel.h"
MyLabel::MyLabel(QString str)
{
zoomnum = 0;
mulsecond = 0;
voicesplitfile = str;
createPixMap();
// DrawGird();
// DrawText();
update();
}
/*void MyLabel::zoom()
{
}*/
void MyLabel::DrawGird()
{
QPainter painter(&wavdestmap);
QPen phonepen(QColor(219,219,219));
phonepen.setWidth(0);
// painter.setPen(wordpen);
QPen wordpen(QColor(238,238,0));
wordpen.setWidth(0);
QPen wordtextpen(QColor(238,122,233));
wordtextpen.setWidth(0);
QPen phonetextpen(QColor(178,58,238));
phonetextpen.setWidth(0);
painter.setWindow(0,0,mulsecond,65535);
QFile file(voicesplitfile);
if(!file.open(QIODevice::ReadOnly|QIODevice::Text)){
return;
}
QTextStream data(&file);
QRegExp reg("WORD");
QRegExp phonereg("PHONE");
bool wordflag = false;
bool phoneflag = false;
while(1){
QString str = data.readLine(0);
if(str.isNull()){
break;
}
if(str.isEmpty()){
continue;
}
if(str.contains(reg)){
if(wordflag){
wordflag = false;
}else{
wordflag = true;
}
}else if(str.contains(phonereg)){
if(phoneflag){
phoneflag = false;
}else{
phoneflag = true;
}
}else{
if(wordflag){
if(str.contains(QRegExp("^[a-zA-z]+"))){
QStringList wordlist = str.split(QRegExp("\\s+"));
if(wordlist.count() >= 4){
painter.setPen(wordpen);
painter.drawLine(wordlist.at(2).toInt(),0,wordlist.at(2).toInt(),65535);
painter.drawLine(wordlist.at(3).toInt(),0,wordlist.at(3).toInt(),65535);
painter.setPen(wordtextpen);
painter.drawText(wordlist.at(2).toInt(),60000,wordlist.at(3).toInt()-wordlist.at(2).toInt(),
5535,Qt::AlignHCenter|Qt::AlignBottom,wordlist.at(0).toLower());
}
}
}
if(phoneflag){
if(str.contains(QRegExp("^[a-zA-z]+"))){
QStringList wordlist = str.split(QRegExp("\\s+"));
if(wordlist.count() >= 4){
painter.setPen(phonepen);
painter.drawLine(wordlist.at(2).toInt(),0,wordlist.at(2).toInt(),65535);
painter.drawLine(wordlist.at(3).toInt(),0,wordlist.at(3).toInt(),65535);
painter.setPen(phonetextpen);
painter.drawText(wordlist.at(2).toInt(),30000,wordlist.at(3).toInt()-wordlist.at(2).toInt(),
5535,Qt::AlignHCenter|Qt::AlignBottom,wordlist.at(0).toLower());
}
}
}
}
}
}
void MyLabel::DrawText()
{
}
void MyLabel::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(0,0,width(),height(),wavdestmap);
}
void MyLabel::ScreenMove()
{
}
void MyLabel::createPixMap()
{
wavsourmap = QPixmap(size());
QPainter painter(&wavsourmap);
QColor pointcolor(0,255,0);
painter.setPen(pointcolor);
QFile file("record.wav");
if(file.open(QIODevice::ReadOnly)){
QDataStream data(&file);
data.setVersion(QDataStream::Qt_4_8);
data.setByteOrder(QDataStream::LittleEndian);
char buf[40];
if(data.readRawData(buf,40) != 40){
setText("WAV's head is error!!");
return;
}
quint32 datanum;
data >> datanum;
mulsecond = datanum / 2;
painter.setWindow(0,-32767,mulsecond,65535);
short tmp;
data >> tmp;
long j = 0;
for(long i = 1; i < mulsecond; i++){
short sampiont;
data >> sampiont;
if(file.error()){
int a = 0;
a++;
return;
}
painter.drawLine(j,tmp,i,sampiont);
j = i;
tmp = sampiont;
}
file.close();
}
wavdestmap = wavsourmap;
return;
}
MyScrollBar::MyScrollBar():QScrollBar()
{
}
void MyScrollBar::zoomstep()
{
}
jdwx
2012-07-24
打赏
举报
回复
将代码拿出来。
dinjay
2012-07-24
打赏
举报
回复
线的坐标算错了吧?
songhuirong1
2012-07-23
打赏
举报
回复
坐标值是否超出label的范围了?
QT 绘图函数
画笔用来
画线
和边缘,
QPainter
::setPen() 可以对画笔进行设置,包括颜色、宽度、线型、拐点风格等。 画刷用来填充几何形状的图案,
QPainter
::setBrush() 可以对画刷进行设置,包括颜色和纹理风格。 绘制文本时...
Qt Creator 的安装和hello world 程序+其他程序的编写--不是一般的好
一、Qt Creator 的安装和hello world 程序的编写(原创) 1.首先到Qt 的官方网站上下载Qt Creator,这里我们下载windows 版的。 ...for Windows* (178Mb) 下载完成后,直接安装即可,安装过程中按默认设置即可。...
Qt框架绘图高级编程、仪表盘、折线图、饼图、柱状图、K线图
课程包括以下内容: Qt
QPainter
绘图常用操作(画图、线、文字、矩形、扇形等) 项目实战一、Qt 绘制汽车仪表盘 项目实战二、Qt 绘制漂亮预警仪表 项目实战三、Qt 实现自绘折线图 Qt 框架之 图表模块QtChart、折线图...
qpainter
斜线 锯齿_
QPainter
:: rotate禁用绘制文本的抗锯齿
我使用
QPainter
::setRenderHint(
QPainter
::Antialiasing, true)来告诉Qt,我希望它能够抗锯齿我所做的任何绘图(在这种情况下,使用
draw
Text()绘制的文本)。
QPainter
:: rotate禁用绘制文本的抗锯齿这工作正常,文本...
QT-
QPainter
绘制曲线等基本图形
Qt中绘制2D图形最核心的一个类是
QPainter
。类
QPainter
是在设备类QPaintDevice上绘制几何图形(包括直线、曲线、圆形、弧形、矩形等等),其中设备类QPaintDevice的子类又有QWidget、QImage、QPictrue、QPixmap、...
Qt
16,203
社区成员
26,591
社区内容
发帖
与我相关
我的任务
Qt
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
复制链接
扫一扫
分享
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章