Hello All,
I'm trying to make a custom TextEditor with some cool features, but I have a show stopper here its the perf of this widget...
I'm drag and dropping a 200Kb text file, and it takes approx 5s to load, where it's near to instantly on most of other standard text editor...
I'm filling the widget like this:
{
// Unpack dropped data and handle it the way you want
// check for our needed mime type, here a file or a list of files
if (mimeData->hasUrls())
{
QList<QUrl> urlList = mimeData->urls();
// extract the local paths of the files
for (int i = 0; i < urlList.size(); ++i)
{
QFile file(urlList.
at(i
).
toLocalFile());
return;
//QString line;
setIsUpdating();
while( !stream.atEnd() ) {
//line = stream.readLine();
this->appendPlainText(stream.readLine());
}
file.close(); // when your done.
setIsUpdating(false);
}
}
}
void logEditor::dropEvent(QDropEvent *de)
{
// Unpack dropped data and handle it the way you want
const QMimeData* mimeData = de->mimeData();
// check for our needed mime type, here a file or a list of files
if (mimeData->hasUrls())
{
QList<QUrl> urlList = mimeData->urls();
// extract the local paths of the files
for (int i = 0; i < urlList.size(); ++i)
{
QFile file(urlList.at(i).toLocalFile());
if (!file.open (QIODevice::ReadOnly))
return;
QTextStream stream ( &file );
//QString line;
setIsUpdating();
while( !stream.atEnd() ) {
//line = stream.readLine();
this->appendPlainText(stream.readLine());
}
file.close(); // when your done.
setIsUpdating(false);
}
}
}
To copy to clipboard, switch view to plain text mode
I have also customized a few things, but I therefore disabling all painting events while i'm filling the text, with the setIsUpdating function.
I also even disabled all the fancy stuff to only have a QPlainTextEdit sublass with the drag and drop event and I still have this slowness.
Full code of the editor can be seen here: http://pastebin.com/1jGtFTX8
I don't really know why is it so slow :/
Any ideas ?
Bookmarks