Qpainter drawline画线

zhz604483686 2012-07-23 04:32:52
在一个label上水平方向均匀画了15条线,就显示出11条,有谁知道是怎么回事吗?
...全文
783 5 打赏 收藏 转发到动态 举报
写回复
用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的范围了?

16,203

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧