Need help to display the preview of the content of file in text browser
-
This is my code snippet:
@
void MainWindow::on_filteredTreeView_clicked(const QModelIndex &index)
{
QString strIndex = index.data(QFileSystemModel::FilePathRole).toString();
QFile file(strIndex);
QFileInfo fileInfo(strIndex);if (fileInfo.suffix() == "txt") { file.open(QIODevice::ReadOnly); QTextStream in(&file); ui->textBrowser->setText(in.readAll()); file.close(); }
}
@I just managed to extract the content of .txt file only to be display in the text browser.
How do I want to extract the content of other file extension such as .jpg, .docx and others? -
@
else if (fileInfo.suffix() == "jpg")
{
QImage my Img(fileInfo.path());
// do something with the image
}
@ -
Thanks to your help.
But, can I ask something?
How do I can output it to the textbrowser? -
[quote author="slumberdin" date="1418114990"]How do I can output it to the textbrowser?[/quote]
That depends on what you want to see in there. Binary data? EXIF information? Some basic picture properties (size, color depth)?
All those are possible, but need to be implemented in a different way.
-
I want to display the image on the text browser.
That means I want to see the image on the text browser.
I don't want to do any change to the property of date modified of the file.
That's why I using read only when I want to read .txt file.
Does the text browser can display the image of .jpg?
Or the text browser can display a bundle of text only? -
QTextBrowser (if we are talking about this widget) can handle HTML, so it should be possible to put in a standard <img> tag there.
But it is much easier to display an image on a QLabel.
-
Yes, text browser can display image.
See example "here":http://qt-project.org/doc/qt-5/qtextedit.html#drag-and-drop -
I managed to display .jpg in my QTextBrowser.
But in the application output, it says:
"QFSFileEngine::open: No file name specified"Can someone explain the this error?
This is my code snippet:
@
else if (fileInfo.suffix() == "jpg" || fileInfo.suffix() == "gif" || fileInfo.suffix() == "png" || fileInfo.suffix() == "tiff" || fileInfo.suffix() == "tiff")
{
QString strPre = QString("<img /> ");
ui->textBrowser->setHtml(strPre);
}
@Edited: Suppose in the line 3, I wrote like this,
src="" + fileInfo.filePath() + "" after "img" and before "/>".I don't know why it don't want to appear.
-
How do I want to open the preview of the content of the .pdf, .docx, .xls and others file type in the QTextBrowser?
Any idea?