PDA

View Full Version : Tabbed QPlainTextEdit



Durkin
23rd July 2013, 13:11
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


setFontCapitalization(QFont::AllUppercase)

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

Lykurg
23rd July 2013, 17:01
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?

Durkin
23rd July 2013, 17:21
Minimal example:


#include <QApplication>
#include <QPlainTextEdit>
#include <QSyntaxHighlighter>

class dummyHighlighter : public QSyntaxHighlighter{
public:
dummyHighlighter(QTextDocument *parent):
QSyntaxHighlighter(parent)
{

}

void highlightBlock(const QString &text){
QTextCharFormat myClassFormat;
myClassFormat.setFontWeight(QFont::Bold);
myClassFormat.setFontCapitalization(QFont::AllUppe rcase);
myClassFormat.setForeground(Qt::darkMagenta);
QString pattern = "(input)";

QRegExp expression(pattern);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, myClassFormat);
index = text.indexOf(expression, index + length);
}
}
};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPlainTextEdit textEdit;
dummyHighlighter highlighter(textEdit.document());

textEdit.show();

return a.exec();
}


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

Durkin
23rd July 2013, 23:40
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.

Lykurg
24th July 2013, 09:46
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.

Durkin
25th July 2013, 02:19
It didn't work on windows either. I could not find this issue on the tracker, therefore I created a new one (https://bugreports.qt-project.org/browse/QTBUG-32619). Feel free to vote for it.