Skip to content

Instantly share code, notes, and snippets.

@mitya57
Last active February 8, 2016 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitya57/0487148ae695223e899a to your computer and use it in GitHub Desktop.
Save mitya57/0487148ae695223e899a to your computer and use it in GitHub Desktop.
#include <QtGui/QFont>
#include <QtWidgets/QApplication>
#include <QtWidgets/QTextEdit>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QTextEdit edit;
edit.resize(640, 480);
edit.setHtml(
"<p style=\"background-color: white;\">"
" <span style=\"color: black\">black</span>"
" <span style=\"color: darkred;\">darkred</span>"
" <span style=\"color: darkgreen;\">darkgreen</span>"
" <span style=\"color: darkblue;\">darkblue</span>"
"</p>"
"<p style=\"background-color: black;\">"
" <span style=\"color: white\">white</span>"
" <span style=\"color: #ff9999;\">lightred</span>"
" <span style=\"color: lightgreen;\">lightgreen</span>"
" <span style=\"color: lightblue;\">lightblue</span>"
"</p>"
"<p style=\"color: black;\">"
" <span style=\"background-color: #ff9999;\">black on red</span>"
" <span style=\"background-color: lightgreen;\">black on green</span>"
" <span style=\"background-color: lightblue;\">black on blue</span>"
"</p>"
"<p style=\"color: white;\">"
" <span style=\"background-color: darkred;\">white on red</span>"
" <span style=\"background-color: darkgreen;\">white on green</span>"
" <span style=\"background-color: darkblue;\">white on blue</span>"
"</p>"
);
edit.setFont(QFont("monospace", 18));
QFontMetrics metrics = edit.fontMetrics();
edit.setCursorWidth(metrics.width(' '));
edit.show();
return app.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment