Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need help to display the preview of the content of file in text browser
Forum Updated to NodeBB v4.3 + New Features

Need help to display the preview of the content of file in text browser

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    slumberdin
    wrote on 9 Dec 2014, 08:16 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 9 Dec 2014, 08:41 last edited by
      #2

      @
      else if (fileInfo.suffix() == "jpg")
      {
      QImage my Img(fileInfo.path());
      // do something with the image
      }
      @

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        slumberdin
        wrote on 9 Dec 2014, 08:49 last edited by
        #3

        Thanks to your help.
        But, can I ask something?
        How do I can output it to the textbrowser?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 9 Dec 2014, 08:58 last edited by
          #4

          [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.

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            slumberdin
            wrote on 9 Dec 2014, 13:52 last edited by
            #5

            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?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 9 Dec 2014, 14:02 last edited by
              #6

              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.

              (Z(:^

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on 9 Dec 2014, 14:03 last edited by
                #7

                Yes, text browser can display image.
                See example "here":http://qt-project.org/doc/qt-5/qtextedit.html#drag-and-drop

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  slumberdin
                  wrote on 10 Dec 2014, 02:32 last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    slumberdin
                    wrote on 10 Dec 2014, 05:39 last edited by
                    #9

                    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?

                    1 Reply Last reply
                    0

                    5/9

                    9 Dec 2014, 13:52

                    • Login

                    • Login or register to search.
                    5 out of 9
                    • First post
                      5/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved