JKQTMathText is a hand-written LaTeX-renderer for Qt (implemented in native C++, using Qt). It supports a large set of standard LaTeX markup and can render it to a QPainter.
This project (see ./examples/jkqtmathtext_simpletest/
) simply creates a QLabel (as a new window) that displays a rendered LaTeX equation (here the time-dependent Schrödinger equation).
The source code of the main application is (see jkqtmathtext_simpletest.cpp
:
#include <QApplication>
#include <QLabel>
#include <QPixmap>
#include "jkqtmathtext/jkqtmathtextlabel.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QLabel lab;
QPixmap pix(600,400);
pix.fill(QColor("white"));
QPainter painter;
mathText.
parse(
"$\\left[-\\frac{\\hbar^2}{2m}\\frac{\\partial^2}{\\partial x^2}+V(x)\\right]\\Psi(x)=\\mathrm{i}\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$");
painter.begin(&pix);
mathText.
draw(painter, Qt::AlignCenter, QRectF(0,0,pix.width(), pix.height()),
false);
painter.end();
lab.setPixmap(pix);
lab.show();
lab.resize(600,400);
return app.exec();
}
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
void draw(QPainter &painter, QPointF x, bool drawBoxes=false)
draw a representation to the object at the specified position x , y
bool parse(const QString &markup, DefaultParserTypes markupType=DefaultParser, ParseOptions options=DefaultParseOptions)
parse the given math markup string with a parser derived from markupType.
bool useXITS(bool mathModeOnly=true, bool useAsFallbackSymbol=true)
configures the class to use the XITS fonts in mathmode
void setFontSize(double __value)
set the default font size in points
The result looks like this: