Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to set QTextBrowser Alignment in setStyleSheet() ?



  • Change all the text to center like:

    ui->textBrowser->setStyleSheet("text-align:center;");
    

    Restore all the text to left:

    ui->textBrowser->setStyleSheet("");
    

  • Lifetime Qt Champion

    Hi
    The text alignment is part of the html/rich text inserted into the widget
    and since each paragraph can have its own alignment ,
    i dont think its possible via Style sheet.



  • ui->textBrowser->selectAll();
    ui->textBrowser->setAlignment(Qt::AlignCenter);
    ......
    ui->textBrowser->selectAll();
    ui->textBrowser->setAlignment(Qt::AlignLeft);
    

Log in to reply