Hi,
I am new in QT. I do some small programes in QT.4.2.2. Now I try to
create a small program, which one draw a line in a particular widget
( label ). I create a form in QT4.2.2 and place three labels in that form named as Label1,
Label2 and Label3 and a pushButton.I need to run the program like this,
when i click on the pushbutton, then a line draw in a label3. How can i
do this?. I create two file like this, Please help me,
Sabeesh C.S

testdraw.h
************************
#ifndef MYQTAPP_H
#define MYQTAPP_H
#include <QWidget>
#include "ui_testdraw.h"
class myQtApp
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
public slots:
void draw();
protected:
};
#endif
#ifndef MYQTAPP_H
#define MYQTAPP_H
#include <QWidget>
#include "ui_testdraw.h"
class myQtApp : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
myQtApp(QWidget *parent = 0);
public slots:
void draw();
protected:
};
#endif
To copy to clipboard, switch view to plain text mode
--------------------------------------------
testdraw.cpp
*************************
#include <QtGui>
#include <qpainter.h>
#include "testdraw.h"
{
setupUi(this);
connect( pushButton, SIGNAL( clicked() ), this, SLOT( draw() ) );
}
painter.setPen(Qt::blue);
painter.
setFont(QFont("Arial",
40));
QLineF line
(10.0,
10.0,
10.0,
120.0);
painter.drawLine(line);
}
void myQtApp::draw() {
qDebug("Hello");
}
#include <QtGui>
#include <qpainter.h>
#include "testdraw.h"
myQtApp::myQtApp(QWidget *parent)
{
setupUi(this);
connect( pushButton, SIGNAL( clicked() ), this, SLOT( draw() ) );
}
void QLabel::paintEvent( QPaintEvent * ) {
QPainter painter( this );
painter.setPen(Qt::blue);
painter.setFont(QFont("Arial", 40));
QLineF line(10.0, 10.0, 10.0, 120.0);
painter.drawLine(line);
}
void myQtApp::draw() {
qDebug("Hello");
}
To copy to clipboard, switch view to plain text mode
------------------------------------
Bookmarks