Results 1 to 6 of 6

Thread: Tabbed QPlainTextEdit

  1. #1
    Join Date
    May 2013
    Posts
    13
    Thanks
    4

    Default Tabbed QPlainTextEdit

    Hello,

    I 'm looking to create a QPlainTextEdit with multiple tabs, like notepad++ or gedit. It would seem that using multiple QPlainTextEdits with a QTabbedWidget is an easy way to accomplish this. However, I 'm wondering how 'heavy' QPlainTextEdit is? Do I really need to have multiple of those, when I basically just need multiple documents?
    I looked to QPlainTextEdit::setDocument though and it suggets that setting another doc would delete the current (if it's not owned by something else). I 'm assuming I would need something to contain and own the documents then.
    Which of the two approaches makes the most sense?

    Also, I was playing around with the syntax highlighter, while most features work fine on QTextcharFormat
    Qt Code:
    1. setFontCapitalization(QFont::AllUppercase)
    To copy to clipboard, switch view to plain text mode 

    does nothing. Any clues what I 'm missing? Thanks.

  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: Tabbed QPlainTextEdit

    notepad++ or gedit are open source. Go and look how they have done it. For a Qt related project look for kate. (second approach sound better to me.)

    For the last question: do you have a minimal example reproducing the problem?

  3. #3
    Join Date
    May 2013
    Posts
    13
    Thanks
    4

    Default Re: Tabbed QPlainTextEdit

    Minimal example:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlainTextEdit>
    3. #include <QSyntaxHighlighter>
    4.  
    5. class dummyHighlighter : public QSyntaxHighlighter{
    6. public:
    7. dummyHighlighter(QTextDocument *parent):
    8. {
    9.  
    10. }
    11.  
    12. void highlightBlock(const QString &text){
    13. QTextCharFormat myClassFormat;
    14. myClassFormat.setFontWeight(QFont::Bold);
    15. myClassFormat.setFontCapitalization(QFont::AllUppercase);
    16. myClassFormat.setForeground(Qt::darkMagenta);
    17. QString pattern = "(input)";
    18.  
    19. QRegExp expression(pattern);
    20. int index = text.indexOf(expression);
    21. while (index >= 0) {
    22. int length = expression.matchedLength();
    23. setFormat(index, length, myClassFormat);
    24. index = text.indexOf(expression, index + length);
    25. }
    26. }
    27. };
    28.  
    29. int main(int argc, char *argv[])
    30. {
    31. QApplication a(argc, argv);
    32. QPlainTextEdit textEdit;
    33. dummyHighlighter highlighter(textEdit.document());
    34.  
    35. textEdit.show();
    36.  
    37. return a.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 

    The word input becomes bold and purple but doesn't turn to uppercase.

  4. #4
    Join Date
    May 2013
    Posts
    13
    Thanks
    4

    Default Re: Tabbed QPlainTextEdit

    I went ahead and implemented a single QPlainTextEdit with multiple tabs and documents (which I made sure had a QPlainTextDocumentLayout). It didn't work - document didn't change as if setDocument didn't do anything. Switching to QTextEdit - no other changes - and it works. To me it seems these two things are bugs but the insight of someone more experienced in Qt would certainly be appreciated.

  5. #5
    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: Tabbed QPlainTextEdit

    About the uppercase issue: interesting. I now remember, that I also went into it... but no solution I have tested it under Linux, you might also check it with windows or mac. Maybe it is a problem with the system font handling but there also some reports at bugreports.qt-project.org. Go and see if there is one which applies to your case, if not, create a new one.

  6. #6
    Join Date
    May 2013
    Posts
    13
    Thanks
    4

    Default Re: Tabbed QPlainTextEdit

    It didn't work on windows either. I could not find this issue on the tracker, therefore I created a new one. Feel free to vote for it.

Similar Threads

  1. Tabbed Notepad
    By "BumbleBee" in forum Newbie
    Replies: 3
    Last Post: 13th October 2011, 20:46
  2. How can I know if a QDockWidget is tabbed?
    By ricardo in forum Qt Programming
    Replies: 1
    Last Post: 8th May 2009, 06:51
  3. Tabbed DockWidget question
    By Banjo in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2008, 10:54
  4. Tabbed QDockWidget question
    By Khal Drogo in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2008, 17:57
  5. QDockWidget Tabbed State
    By jtaylor108 in forum Newbie
    Replies: 2
    Last Post: 2nd August 2007, 00:16

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.