Results 1 to 7 of 7

Thread: Qt line number in text editor

  1. #1
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt line number in text editor

    Hello;

    I have been looking for my issue for somes weeks but I didn' achieve to solve it.

    I'm trying to put line numbers on the left side of my QSubWindow but I have a compilation error using the Qt exemple: 'QWidget' is an ambiguous base of 'MainFen'

    I don't understand the error.
    Could you help me please?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt line number in text editor

    MainFen has which base classes? Please show some code that we better can see, what you are doing wrong.

  3. #3
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt line number in text editor

    oh sorry :

    Qt Code:
    1. class MainFen : public QMainWindow, public QPlainTextEdit, private Ui::MainFen
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. MainFen(QWidget *parent = 0);
    8. ~MainFen();
    9.  
    10. void lineNumberAreaPaintEvent(QPaintEvent *event);
    11. int lineNumberAreaWidth();
    12.  
    13. private slots:
    14.  
    15. void updateLineNumberAreaWidth(int newBlockCount);
    16. void updateLineNumberArea(const QRect &, int);
    17.  
    18. protected:
    19. void resizeEvent(QResizeEvent *event);
    20.  
    21. private:
    22.  
    23. QMdiArea * centralZone;
    24. QMdiSubWindow * Win;
    25. QPlainTextEdit * textEdit;
    26.  
    27. QWidget * lineNumberArea;
    28.  
    29. };
    To copy to clipboard, switch view to plain text mode 

    So MainFen has public QMainWindow, public QPlainTextEdit, private Ui::MainFen base classes.

    and that's the LineNumberArea class from Qt exemple:

    Qt Code:
    1. class LineNumberArea : public QMdiSubWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. LineNumberArea(MainFen * main) : QMdiSubWindow(main)
    8. {
    9. mainfen = main;
    10. }
    11.  
    12. QSize sizeHint() const
    13. {
    14. return QSize(mainfen->lineNumberAreaWidth(), 0);
    15. }
    16.  
    17.  
    18. protected:
    19.  
    20. void paintEvent(QPaintEvent *event)
    21. {
    22. mainfen->lineNumberAreaPaintEvent(event);
    23. }
    24.  
    25.  
    26. private:
    27.  
    28. MainFen * mainfen;
    29.  
    30. };
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt line number in text editor

    Hi, MainFen is derived of two QWidget based Widgets: QMainWindow and QPlainTextEdit. I am not sure if that is allowed at all.

    Ginsengelf
    Last edited by Ginsengelf; 24th August 2010 at 08:59. Reason: spelling corrections

  5. #5
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt line number in text editor

    Yes this is not allowed but how should I do?

  6. #6
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt line number in text editor

    Just derive from QMainWindow only and use QPlainTextEdit as a member (you already have the pointer).

    Ginsengelf

  7. #7
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt line number in text editor

    If I only inherit from QMainWindow I have other errors other errors

Similar Threads

  1. Replies: 1
    Last Post: 22nd July 2010, 18:12
  2. How to get Line Number in QWebView
    By nish in forum Qt Programming
    Replies: 0
    Last Post: 16th December 2009, 14:02
  3. How to read line number in a text file
    By grsandeep85 in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2009, 10:09
  4. count line number in text
    By Alina in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 09:29
  5. a Text Editor with line numbers...
    By fullmetalcoder in forum Qt Programming
    Replies: 47
    Last Post: 5th April 2006, 12:10

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.