improved high-dpr-support in JKQTMathText

This commit is contained in:
jkriege2 2022-06-02 22:17:38 +02:00
parent fd2ae94c6c
commit bf21d53149
4 changed files with 18 additions and 15 deletions

View File

@ -17,6 +17,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>fixed issue described in <a href="https://github.com/jkriege2/JKQtPlotter/pull/62">#62: Fix custom labels draw, because giving exactly two label-strings did not display all of them</a>, thanks to <a href="https://github.com/FalsinSoft">user:FalsinSoft</a></li>
<li>fixed issue <a href="https://github.com/jkriege2/JKQtPlotter/pull/70">#70: Typo in jkqtplotter/CMakeLists.txt</a>, thanks to <a href="https://github.com/tedlinlab">user:tedlinlab</a></li>
<li>fixed: styling was not properly applied to coordinate axes of colorbars outside the plot</li>
<li>improved: high-dpr-support in JKQTMathText</li>
<li>NEW: JKQTPFilledCurveXGraph and JKQTPFilledCurveYGraph can now plot wiggle plots with different fill styles above and below the baseline (feature request <a href="https://github.com/jkriege2/JKQtPlotter/issues/68">#68 Wiggle Plots</a> from <a href="https://github.com/xichaoqiang">user:xichaoqiang</a> </li>
<li>NEW/BREAKING CHANGE: data tooltip can now also be shown when "just" moving the mouse (so far this was only possible when dragging the mouse with a button pressed). This also removes JKQtPlotter::getActMouseLeftAsToolTip() and adds JKQtPlotter::getActMouseMoveToolTip() instead! Also the default toolbars and context menus changed!</li>
<li>NEW: new "seaborn" style for plots</li>

View File

@ -23,7 +23,9 @@ int main(int argc, char* argv[])
QLabel lab;
// 1. we will paint into a QPixmap
QPixmap pix(600,400);
const qreal dpr = lab.devicePixelRatioF();
QPixmap pix(600*dpr,400*dpr);
pix.setDevicePixelRatio(dpr);
pix.fill(QColor("white"));
QPainter painter;
@ -40,7 +42,7 @@ int main(int argc, char* argv[])
// 3. here we do the painting
painter.begin(&pix);
mathText.draw(painter, Qt::AlignCenter, QRectF(0,0,pix.width(), pix.height()), false);
mathText.draw(painter, Qt::TopLeftCorner, QRectF(0,0,pix.width(), pix.height()), false);
painter.end();
// now we display and resize the label as a window

View File

@ -226,7 +226,7 @@ TestForm::~TestForm()
delete ui;
}
#define W 2000
#define W 3000
#define H 2000
#define X1 15
#define Y1 50
@ -390,8 +390,10 @@ void TestForm::updateMath()
ui->scrollArea->setBackgroundRole(QPalette::Dark);
QPixmap pix(W, H);
const qreal dpr = devicePixelRatioF();
QPixmap pix(W*dpr, H*dpr);
pix.fill();
pix.setDevicePixelRatio(dpr);
QPainter painter;
JKQTMathText mt(this);

View File

@ -4780,8 +4780,11 @@ void JKQTMathTextLabel::internalPaint()
if (!m_mathText->parse(lastText)) {
//qDebug()<<"JKQTMathTextLabel::internalPaint(): parse '"<<lastText<<"': "<<m_mathText->parse(lastText)<<"\n "<<m_mathText->getErrorList().join("\n")<<"\n\n";
}
if (buffer.width()<=0 || buffer.height()<=0) buffer=QPixmap(1000,100);
if (buffer.width()<=0 || buffer.height()<=0) {
const qreal dpr = devicePixelRatioF();
buffer=QPixmap(1000*dpr,100*dpr);
buffer.setDevicePixelRatio(dpr);
}
//qDebug()<<"internalPaint(): buffer "<<buffer.size();
QPainter p;
//qDebug()<<"internalPaint(): "<<p.begin(&buffer);
@ -4794,10 +4797,12 @@ void JKQTMathTextLabel::internalPaint()
size=m_mathText->getSize(p);
p.end();
}
buffer=QPixmap(static_cast<int>(qMax(32.0,size.width()*1.2)), static_cast<int>(qMax(10.0,size.height()*1.1)));
const qreal dpr = devicePixelRatioF();
buffer=QPixmap(static_cast<int>(qMax(32.0,size.width()*1.2))*dpr, static_cast<int>(qMax(10.0,size.height()*1.1))*dpr);
buffer.setDevicePixelRatio(dpr);
buffer.fill(Qt::transparent);
{
//qDebug()<<"internalPaint(): "<<buffer.size()<<size;
qDebug()<<"internalPaint(): buffer.size()="<<buffer.size()<<" size="<<size<<" dpr="<<dpr;
QPainter p;
//qDebug()<<"internalPaint(): "<<p.begin(&buffer);
p.begin(&buffer);
@ -4818,14 +4823,7 @@ void JKQTMathTextLabel::internalPaint()
void JKQTMathTextLabel::paintEvent(QPaintEvent *event)
{
//QLabel::paintEvent(event);
//return;
//qDebug()<<"paintEvent: "<<buffer.size();
//QApplication::processEvents();
QLabel::paintEvent(event);
//qDebug()<<"paintEvent DONE: "<<size();
}