Results 1 to 9 of 9

Thread: Urgent Help regarding Line numbering

  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.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Urgent Help regarding Line numbering

    Why don't you just copy the class CodeEditor from the example and use it as it is.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    Default Re: Urgent Help regarding Line numbering

    @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.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Urgent Help regarding Line numbering

    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?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    Default Re: Urgent Help regarding Line numbering

    @Santosh Sir, sorry I posted wrong image. This is the updated one..img1.jpg..with multiple widgets..

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Urgent Help regarding Line numbering

    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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    Default Re: Urgent Help regarding Line numbering

    Thank you very much @Santosh Sir...was stuck at this from so long.. Finally able to do it... Thanks a lott....

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

    Default Re: Urgent Help regarding Line numbering

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

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Urgent Help regarding Line numbering

    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.

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.