mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-26 18:41:40 +08:00
df257a6b1a
improved documentation
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
/** \example jkqtmathtext_simpletest.cpp
|
|
* A very basic example for the usage of JKQTMathText
|
|
*
|
|
* \ref JKQTMathTextSimpleExample
|
|
*/
|
|
|
|
#include <QApplication>
|
|
#include <QLabel>
|
|
#include <QPixmap>
|
|
#include "jkqtmathtext/jkqtmathtext.h"
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
QApplication app(argc, argv);
|
|
|
|
// we use a simple label to display the math text
|
|
QLabel lab;
|
|
|
|
// 1. we will paint into a QPixmap
|
|
QPixmap pix(600,400);
|
|
pix.fill(QColor("white"));
|
|
QPainter painter;
|
|
|
|
// 2. now we create a JKQTMathText object.
|
|
// Also we configure the JKQTMathText to use the XITS fonts that
|
|
// were included in the *.pro-file
|
|
JKQTMathText mathText;
|
|
mathText.useXITS();
|
|
mathText.setFontSize(20);
|
|
|
|
// 3. now we parse some LaTeX code (the Schroedinger's equation), so
|
|
// we can draw it onto the QPixmap in the next step
|
|
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)$");
|
|
|
|
// 3. here we do the painting
|
|
painter.begin(&pix);
|
|
mathText.draw(painter, Qt::AlignCenter, QRectF(0,0,pix.width(), pix.height()), false);
|
|
painter.end();
|
|
|
|
// now we display and resize the label as a window
|
|
lab.setPixmap(pix);
|
|
lab.show();
|
|
lab.resize(600,400);
|
|
|
|
return app.exec();
|
|
}
|