Results 1 to 9 of 9

Thread: Urgent Help regarding Line numbering

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Urgent Help regarding Line numbering

    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

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3. #include<frameclass.h>
    4. #include <QMainWindow>
    5. #include<frameclass.h>
    6. #include<Painter.h>
    7.  
    8. namespace Ui {
    9. class MainWindow;
    10. }
    11.  
    12. class MainWindow : public QMainWindow
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit MainWindow(QWidget *parent = 0);
    18.  
    19.  
    20. ~MainWindow();
    21.  
    22.  
    23.  
    24.  
    25.  
    26. private:
    27. Ui::MainWindow *ui;
    28.  
    29. };
    30.  
    31. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include<qtextcursor.h>
    4. #include<frameclass.h>
    5. #include<qpainter.h>
    6. #include<Painter.h>
    7.  
    8. MainWindow::MainWindow(QWidget *parent) :
    9. QMainWindow(parent),
    10. ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13.  
    14.  
    15. }
    16.  
    17.  
    18.  
    19. MainWindow::~MainWindow()
    20. {
    21. delete ui;
    22. }
    To copy to clipboard, switch view to plain text mode 



    I have created a separate class "frameclass.h" to implement paint event.

    frameclass.h

    Qt Code:
    1. #ifndef FRAMECLASS_H
    2. #define FRAMECLASS_H
    3. #include<QWidget>
    4. #include<QFrame>
    5. #include<qpainter.h>
    6. #include<qmainwindow.h>
    7. #include<QTextBlock>
    8.  
    9.  
    10.  
    11.  
    12.  
    13. class frameclass : public QFrame
    14. {
    15.  
    16. Q_OBJECT
    17. public:
    18. frameclass( QWidget * parent) : QFrame(parent)
    19. {
    20.  
    21.  
    22. }
    23.  
    24.  
    25. void paintEvent( QPaintEvent * event )
    26. {
    27. QFrame::paintEvent(event);
    28.  
    29.  
    30.  
    31. QPainter p(this);
    32. QRect r = rect();
    33.  
    34. p.setPen(Qt::red);
    35.  
    36. p.drawText(r, Qt::AlignCenter, "hello");
    37.  
    38. //p.drawRect(r);
    39. p.fillRect(r,Qt::lightGray);
    40.  
    41.  
    42.  
    43.  
    44.  
    45.  
    46.  
    47. //p.drawLine( rect().topLeft(), rect().bottomRight() );
    48. //p.drawText( rect().center(), "works!" );
    49. }
    50. };
    51.  
    52.  
    53.  
    54. #endif // FRAMECLASS_H
    To copy to clipboard, switch view to plain text mode 



    frameclass.cpp

    Qt Code:
    1. #include "frameclass.h"
    2.  
    3.  
    4. frameclass::frameclass()
    5. {
    6.  
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 


    For line numbering, I have been following this example.

    http://qt-project.org/doc/qt-4.8/wid...odeeditor.html

    This is how my Ui looks like...

    img1.jpg


    Can anyone please help me out with this so as to how can i introduce line numbering??
    Last edited by aaditya190; 11th December 2013 at 06:11.

Similar Threads

  1. Line numbering of a plaintextedit
    By aaditya190 in forum Newbie
    Replies: 5
    Last Post: 10th December 2013, 05:44
  2. line numbering in textedit
    By aaditya190 in forum Newbie
    Replies: 6
    Last Post: 6th December 2013, 06:38
  3. line numbering in text editor.
    By parulkalra in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2013, 20:21
  4. Line Numbering in textedit
    By aaditya190 in forum Newbie
    Replies: 2
    Last Post: 15th November 2013, 08:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.