0

Is there possibility to easily increase spaces between words in QTextEdit? My only idea is to set space key event to insert more whitespaces, but i would better like some setting parameters solution?

Is there way to set words in columns in text edit. What I mean:

first word       wordabc      abcd
second word      worda        egdsa
third word       wordb        dafdd

With this I have no idea for now.

krzych
  • 2,126
  • 7
  • 31
  • 50

2 Answers2

0

The QTextEdit can render html, so you could use table elements to achieve what you want.

#include <QtGui/QApplication>
#include <QtGui/QTextEdit>

int main(int argc, char *argv[])
{
  QString html = "<html><body><table>";
  html += "<tr><td>first word</td><td>wordabc</td><td>abcd</td></tr>";
  html += "<tr><td>second word</td><td>worda</td><td>egdsa</td></tr>";
  html += "<tr><td>third word</td><td>wordb</td><td>dafdd</td></tr>";
  html += "</table></body></html>";

  QApplication app(argc, argv);
  QTextEdit textEdit;
  textEdit.setHtml(html);
  textEdit.show();
  return app.exec();
}

You could also apply styling to the table for example by adding the width attribute to the td tag to push columns apart from each other.

acraig5075
  • 10,588
  • 3
  • 31
  • 50
  • And how to save document then without html tags? Also each space key event must add tag, and ther will be hard to define columns amount. – krzych Jul 12 '12 at 21:27
  • I see your question is more complicated than what I thought. I'm thinking that `QTextEdit` is not appropriate and the input of the columnar data would be better handled in a `QTableWidget`. – acraig5075 Jul 13 '12 at 06:13
  • It's supposed to be some code editor. I want to set commands and parameters in columns to be better readable (some kind of autoformating) – krzych Jul 16 '12 at 08:17
0

You can apply QTextCharFormat to your text and use QTextCharFormat::setFontWordSpacing ( qreal spacing )

hank
  • 9,553
  • 3
  • 35
  • 50
  • Increases spacing, but words are not in columns. This is key condition because functionality ought to improve readability of commands. – krzych Jul 16 '12 at 19:24
  • So your question is not about text decoration but about text markup. That's why you should use some markup language as advised above. – hank Jul 17 '12 at 09:50
  • But the parameters number varies for different commands and also what with saving files without tags? – krzych Jul 17 '12 at 11:57