qtextbrowser text view problem



  • i output a text from qprosess and plase it qtextbrowser .

    but problem is , how text is shown in textbrowser .also text warp is not working.

    0_1525175264437_uy.png

    is it possible to set text as terminal text ? i am talking about spaces between text ?



  • before writing anything in it, you can use

    textBrowser->setLineWrapMode(QTextEdit::NoWrap);
    textBrowser->setCurrentFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
    


  • @VRonin
    0_1525252457628_a1.png

    spacing is not fixed



  • Text browser is just ignoring textBrowser->setCurrentFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));

    Let's try this:

    QTextCursor textBrowCrsr(ui->tdetail->document());
    const int oldPos = textBrowCrsr.position();
    textBrowCrsr.movePosition(QTextCursor::End);
    QTextCharFormat textBrowFormat = textBrowCrsr.charFormat();
    textBrowFormat.setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
    textBrowCrsr.insertText(output,textBrowFormat);
    textBrowCrsr.setPosition(oldPos);
    

    P.S.
    That's not a great way of reading from QProcess to QString. It probably blows up as soon as you have any non-ASCII char. Use QTextStream instead



  • @VRonin said in qtextbrowser text view problem:

    QTextStream

    i tried it ,but no changes.

    please see the cpp file github
    i need the fix for my next release .
    so please give me a fix.

    0_1525426582991_f.png

    please show me how to use the QTextStream in that function .



  • The problem in your screenshot is that the last row (setText) overrides everything done above. just remove that row.

    how to use the QTextStream

    replace QString output(pl.readAllStandardOutput()); with

    QTextStream consoleStream(&pl);
    const QString output  = consoleStream.readAll();
    


  • @VRonin nothing
    0_1525496871078_i.png



  • @VRonin any other solution??


  • Lifetime Qt Champion

    Hi,

    You should add some checks to verify that the process did indeed run and it was successful.



  • @SGaist
    it run successfully and output is on the side window.


  • Lifetime Qt Champion

    The fact that mediainfo runs successfully on the command line doesn't mean that it will necessarily run the way you expect it to with QProcess.

    Are you sure the path to the media file you are using is correct ?
    Is it a relative or are an absolute path ?
    What if you use the recommended structure of calling QProcess::start with the command as first parameter and a QStringList with the options as second parameter ?
    Did you actually checked that p1 starts successfully ?
    Did you actually checked that p1 ends successfully ?


  • Qt Champions 2017

    Hi
    As for other solution.
    Use a QplainTextEdit
    alt text

    and just sets its font to monospaced
    ui->plainTextEdit->setFont( (QFontDatabase::systemFont(QFontDatabase::FixedFont)) );



  • The only thing I can think of with QTextBrowser is that you are using a style sheet with a font that overrides the one we are setting


  • Qt Champions 2017

    @VRonin
    Yep something like that - as your code and test file just works
    with output from same command on linux.

    Also, i noticed one thing in code shown on GITHUB

    QTextCursor textBrowCrsr(ui->tdetail->document());
        const int oldPos = textBrowCrsr.position();
        textBrowCrsr.movePosition(QTextCursor::End);
        QTextCharFormat textBrowFormat = textBrowCrsr.charFormat();
        textBrowFormat.setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
        textBrowCrsr.insertText(output,textBrowFormat);
        textBrowCrsr.setPosition(oldPos);
    
    
        ui->tdetail->setText(output.toUtf8()); <<<<<<<<<<<<<<<<<< wont that override insertText ?
    


  • @mrjj it was a old commit .


  • Qt Champions 2017

    @saber
    ok.
    I did make small test on linux and VRonin sample did in fact make
    it uses fixed font so it looked correctly.
    However, using plainTextEdit is a one liner so might be more optimal if you do not need the HTML textbrowse offer



  • i do't know how to fix that or what's wrong.
    after long works i made an app with mediainfo as backend.
    here is the app CoreInfo.
    thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.