Ohmu11
4th February 2015, 18:00
my data in text file like this
1.5
2.0
1.23
2.67
I would like to drawline vertical axis.Now i have no idea plz.
my code.
#include "dialog.h"
#include "ui_dialog.h"
#include<QPainter>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
// bool w_flag = false;
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pushButton_2_clicked()
{
m_fill = !m_fill;
readfile();
update();
}
void Dialog::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
if(m_fill)
{
painter.setPen( QPen(Qt::red, 2,Qt::SolidLine) );
painter.drawLine( 300, 300, 800,300);
}
}
void Dialog::readfile()
{
QString filename1 = "data.txt";//readfile
QFile file1(filename1);
file1.open(QIODevice::ReadOnly|QIODevice::Text);
QTextStream in(&file1);
QString init = in.readLine();
file1.close();
}
1.5
2.0
1.23
2.67
I would like to drawline vertical axis.Now i have no idea plz.
my code.
#include "dialog.h"
#include "ui_dialog.h"
#include<QPainter>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
// bool w_flag = false;
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pushButton_2_clicked()
{
m_fill = !m_fill;
readfile();
update();
}
void Dialog::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
if(m_fill)
{
painter.setPen( QPen(Qt::red, 2,Qt::SolidLine) );
painter.drawLine( 300, 300, 800,300);
}
}
void Dialog::readfile()
{
QString filename1 = "data.txt";//readfile
QFile file1(filename1);
file1.open(QIODevice::ReadOnly|QIODevice::Text);
QTextStream in(&file1);
QString init = in.readLine();
file1.close();
}