2019-01-13 01:53:16 +08:00
|
|
|
/** \example jkqtmathtext_simpletest.cpp
|
2019-01-20 17:49:29 +08:00
|
|
|
* A very basic example for the usage of JKQTMathText
|
2019-01-13 01:53:16 +08:00
|
|
|
*
|
2019-01-20 17:49:29 +08:00
|
|
|
* \ref JKQTMathTextSimpleExample
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPixmap>
|
2022-06-08 21:38:26 +08:00
|
|
|
#include "jkqtmathtext/jkqtmathtextlabel.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2022-04-22 19:27:31 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
2022-04-16 05:01:09 +08:00
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); //HiDPI pixmaps
|
|
|
|
#endif
|
2018-12-29 00:46:47 +08:00
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
// we use a simple label to display the math text
|
|
|
|
QLabel lab;
|
|
|
|
|
|
|
|
// 1. we will paint into a QPixmap
|
2022-06-03 04:17:38 +08:00
|
|
|
const qreal dpr = lab.devicePixelRatioF();
|
|
|
|
QPixmap pix(600*dpr,400*dpr);
|
|
|
|
pix.setDevicePixelRatio(dpr);
|
2018-12-29 00:46:47 +08:00
|
|
|
pix.fill(QColor("white"));
|
|
|
|
QPainter painter;
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
// 2. now we create a JKQTMathText object.
|
|
|
|
// Also we configure the JKQTMathText to use the XITS fonts that
|
2018-12-29 00:46:47 +08:00
|
|
|
// were included in the *.pro-file
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTMathText mathText;
|
2018-12-29 00:46:47 +08:00
|
|
|
mathText.useXITS();
|
2019-01-26 03:16:04 +08:00
|
|
|
mathText.setFontSize(20);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 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);
|
2022-06-03 04:17:38 +08:00
|
|
|
mathText.draw(painter, Qt::TopLeftCorner, QRectF(0,0,pix.width(), pix.height()), false);
|
2018-12-29 00:46:47 +08:00
|
|
|
painter.end();
|
|
|
|
|
|
|
|
// now we display and resize the label as a window
|
|
|
|
lab.setPixmap(pix);
|
|
|
|
lab.show();
|
|
|
|
lab.resize(600,400);
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|