PDA

View Full Version : Urgent Help regarding Line numbering



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??

Santosh Reddy
11th December 2013, 08:18
Why don't you just copy the class CodeEditor from the example and use it as it is.

aaditya190
11th December 2013, 10:07
@Santosh Sir, I would have copied the entire code if there if I would have required only one textedit and its line numbers. I have a Ui containing multiple widgets as i posted in the previous post the image of my Ui.. I wish to pass the Ui object of textedit to the CodeEditor class. Can you suggest me how to do this? This is mainly what I am looking for. Any help would be appreciable.

Santosh Reddy
11th December 2013, 10:22
I am not able to understand your requirement.


I have a Ui containing multiple widgets as i posted in the previous post the image of my Ui..
The UI you posted is a MainWindow containing a textedit. Where are the multiple widgets in it?


I wish to pass the Ui object of textedit to the CodeEditor class. Can you suggest me how to do this?
CodeEditor itself is a textedit. What is the UI you are talking about?

aaditya190
11th December 2013, 10:28
@Santosh Sir, sorry I posted wrong image. This is the updated one..9844..with multiple widgets..

Santosh Reddy
11th December 2013, 10:41
Looks like you want to insert CodeEdit from Qt Designer, If yes you have two options.
1. Make a Qt Designer plungin for CodeEdit
or
2. Add a regular QWidget in UI and promote it to CodeEdit.

aaditya190
11th December 2013, 10:57
Thank you very much @Santosh Sir...was stuck at this from so long.. Finally able to do it... Thanks a lott....:)

aaditya190
6th January 2014, 10:47
@Santosh Sir, I have one more question. Sorry posted a few threads about this but didn't get any replies so I am continuing this thread. I have a doubt regarding regular expressions.

Can we write a single piece of code for all the operators instead of writing code for each and every operator to include them as a regular expression?




QRegExp rx;



I wish to initialize rx in such a way that it should include all arithmetic operators. Is there a way out for this? Can nyone please help me out?

ChrisW67
6th January 2014, 20:33
You have already asked this question (and several others like it) in its own thread. You received a response asking you to define the problem better and giving you a suggestion on how to improve your understanding... that you just ignored. I suggest you start reading responses you get rather than simply asking the same questions over and over until someone gives you something you can copy and paste without understanding.