Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    3
    9
    1588
    Loading More Posts
    • 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
      slumberdin last edited by

      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 Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

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

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • S
          slumberdin last edited by

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

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            [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 Reply Quote 0
            • S
              slumberdin last edited by

              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 Reply Quote 0
              • sierdzio
                sierdzio Moderators last edited by

                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 Reply Quote 0
                • A
                  andreyc last edited by

                  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 Reply Quote 0
                  • S
                    slumberdin last edited by

                    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 Reply Quote 0
                    • S
                      slumberdin last edited by

                      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 Reply Quote 0
                      • First post
                        Last post