0

In C++,I am trying to set line height.

if (auto message = guideMsgWidget->getMessageTextEdit())
{
    message->setTextStyle("font-size: 12px; text-align: left; color: #1b1b1e;");
}

Here's the thing. getMessageTextEdit() function returns component which inherit QWidget. So I'm tring to put line height in setstylesheet. But it doesn't work.

I've tried using QTextBlockFormat and Cursor.

here's one of code that i've tried.

if (auto message = guideMsgWidget->getMessageTextEdit())
{
    QString existingStyle = message->styleSheet();
    QString newStyle = QString("QTextEdit {%1 line-height: 1.5;}").arg(existingStyle);
    message->setStyleSheet(newStyle);
}
Chae
  • 9
  • 2
  • Hi, I am not sure what you want to achieve. Do you want to increase the font size? Do you want to increase the space between two lines of text? If not, what is the purpose of increasing the line height? – Pamputt Jun 08 '23 at 08:41
  • 1
    Is `line-height` a valid style sheet property? – G.M. Jun 08 '23 at 08:43
  • Can you provide more info about your class that inherits QWidget ? does it contains a QTextEdit as an attribute ? – Oka Jun 08 '23 at 08:45
  • 1
    I couldn't find anything about `line-height` in Qt stylesheet docs, not all CSS works with Qt. – Abderrahmene Rayene Mihoub Jun 08 '23 at 08:47
  • yes my bad after checking, it is not usable with Qt stylesheets ... – Oka Jun 08 '23 at 08:50
  • Your code is incomplete; in particular, it seems to be missing a `main()` function and at least one `#include`. Please [edit] your code so it's a [mcve] of your problem (including any necessary inputs, but preferably not needing any), then we can try to reproduce and solve it. You should also read [ask]. – Toby Speight Jun 08 '23 at 09:31
  • Does this help: [QTextEdit sets fix line Height, paragraph spacing](https://stackoverflow.com/questions/18909507/qtextedit-sets-fix-line-height-paragraph-spacing) – Abderrahmene Rayene Mihoub Jun 08 '23 at 09:44

0 Answers0