aaditya190
11th December 2013, 06:00
I have been posting various threads but not able to get a fruitful reply. I have been trying to introduce line numbering in a text edit..I would like to post all the code that i have done till now.
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include<frameclass.h>
#include <QMainWindow>
#include<frameclass.h>
#include<Painter.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<qtextcursor.h>
#include<frameclass.h>
#include<qpainter.h>
#include<Painter.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
I have created a separate class "frameclass.h" to implement paint event.
frameclass.h
#ifndef FRAMECLASS_H
#define FRAMECLASS_H
#include<QWidget>
#include<QFrame>
#include<qpainter.h>
#include<qmainwindow.h>
#include<QTextBlock>
class frameclass : public QFrame
{
Q_OBJECT
public:
frameclass( QWidget * parent) : QFrame(parent)
{
}
void paintEvent( QPaintEvent * event )
{
QFrame::paintEvent(event);
QPainter p(this);
QRect r = rect();
p.setPen(Qt::red);
p.drawText(r, Qt::AlignCenter, "hello");
//p.drawRect(r);
p.fillRect(r,Qt::lightGray);
//p.drawLine( rect().topLeft(), rect().bottomRight() );
//p.drawText( rect().center(), "works!" );
}
};
#endif // FRAMECLASS_H
frameclass.cpp
#include "frameclass.h"
frameclass::frameclass()
{
}
For line numbering, I have been following this example.
http://qt-project.org/doc/qt-4.8/widgets-codeeditor.html
This is how my Ui looks like...
9842
Can anyone please help me out with this so as to how can i introduce line numbering??
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include<frameclass.h>
#include <QMainWindow>
#include<frameclass.h>
#include<Painter.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<qtextcursor.h>
#include<frameclass.h>
#include<qpainter.h>
#include<Painter.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
I have created a separate class "frameclass.h" to implement paint event.
frameclass.h
#ifndef FRAMECLASS_H
#define FRAMECLASS_H
#include<QWidget>
#include<QFrame>
#include<qpainter.h>
#include<qmainwindow.h>
#include<QTextBlock>
class frameclass : public QFrame
{
Q_OBJECT
public:
frameclass( QWidget * parent) : QFrame(parent)
{
}
void paintEvent( QPaintEvent * event )
{
QFrame::paintEvent(event);
QPainter p(this);
QRect r = rect();
p.setPen(Qt::red);
p.drawText(r, Qt::AlignCenter, "hello");
//p.drawRect(r);
p.fillRect(r,Qt::lightGray);
//p.drawLine( rect().topLeft(), rect().bottomRight() );
//p.drawText( rect().center(), "works!" );
}
};
#endif // FRAMECLASS_H
frameclass.cpp
#include "frameclass.h"
frameclass::frameclass()
{
}
For line numbering, I have been following this example.
http://qt-project.org/doc/qt-4.8/widgets-codeeditor.html
This is how my Ui looks like...
9842
Can anyone please help me out with this so as to how can i introduce line numbering??