How to rotate these text?
-
Translation works with these:
void Axis::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){ painter->setRenderHints(QPainter::Antialiasing); painter->setPen(QPen(Qt::gray, 1, Qt::DashLine)); painter->translate(0, m_rect.height()); painter->scale(1, -1); float space = (m_rect.height() - m_labelHeight) / 5; float increment = m_max / 5; float start = 0, numStart = 0; QFontMetrics fm(painter->font()); for(int i = 0; i < 6; i++){ painter->drawLine(0, start, m_rect.width(), start); painter->save(); auto label = QString::number(roundf(numStart)); painter->translate(0, fm.boundingRect(label).height()); //painter->scale(1, -1); painter->drawText(QPointF(0, start), label); painter->restore(); start += space; numStart += increment; } }
BUT couldn't fix the rotation. Here's how the label looks:
-
Hi,
Are looking for QPainter::rotate ?
-
Hi,
Are looking for QPainter::rotate ?
@SGaist, tried that several times last night but those text remains flipped
-
Hi,
Are looking for QPainter::rotate ?
@SGaist, that's a crazy equation:
void Axis::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){ painter->setRenderHints(QPainter::Antialiasing); painter->setPen(QPen(Qt::gray, 1, Qt::DashLine)); painter->translate(0, m_rect.height()); painter->scale(1, -1); int step = 5; float space = (m_rect.height() - m_labelHeight) / step; float increment = m_max / step; float start = 0, numStart = 0; QFontMetrics fm(painter->font()); for(int i = 0; i < 6; i++){ painter->drawLine(0, start, m_rect.width(), start); painter->save(); auto label = QString::number(roundf(numStart)); painter->scale(1, -1); //painter->translate(0, fm.boundingRect(label).height()); painter->drawText(QPointF(0, -m_rect.height() + (step - i) * space + fm.boundingRect(label).height()), label); painter->restore(); start += space; numStart += increment; } }
but works:
-
Each Bar has its own
paint
and each of them is a separateGraphicsItem
BUT why do they rotate like this:if I uncomment
painter->rotate(-15);
, in the following block, I get the output shown on the right:void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){ painter->setRenderHints(QPainter::Antialiasing); painter->setBrush(Qt::black); painter->setPen(Qt::NoPen); painter->translate(0, m_rect.height()); painter->scale(1.0, -1.0); float h1 = m_series.value1 / m_max * (m_rect.height() - m_axisLabelHeight - m_labelHeight); float h2 = m_series.value2 / m_max * (m_rect.height() - m_axisLabelHeight - m_labelHeight); auto rect = QRectF(m_rect.left(), m_labelHeight, m_rect.width(), h1); painter->drawRect(rect); painter->setBrush(Qt::gray); rect = QRectF(m_rect.left(), m_labelHeight +h1, m_rect.width(), h2); painter->drawRect(rect); painter->setPen(Qt::gray); painter->scale(1, -1); //painter->rotate(-15); painter->drawText(m_rect.left(), 0, m_series.name); }
-
I would add save and restore calls on your QPainter object.
-
@SGaist, if I do this:
... painter->save(); painter->scale(1, -1); painter->rotate(-15); painter->drawText(m_rect.left(), 0, m_series.name); painter->restore();
or:
... painter->scale(1, -1); painter->save(); painter->rotate(-15); painter->drawText(m_rect.left(), 0, m_series.name); painter->restore();
I get same result. Uploaded the project in GitHub.
-
@SGaist, if I do this:
... painter->save(); painter->scale(1, -1); painter->rotate(-15); painter->drawText(m_rect.left(), 0, m_series.name); painter->restore();
or:
... painter->scale(1, -1); painter->save(); painter->rotate(-15); painter->drawText(m_rect.left(), 0, m_series.name); painter->restore();
I get same result. Uploaded the project in GitHub.
@Emon-Haque The objective of GitHub is not to share zip but to upload all files (.cpp, .h and others). This way it is easier to analyze the code, report issues and send pull requests
-
@Emon-Haque The objective of GitHub is not to share zip but to upload all files (.cpp, .h and others). This way it is easier to analyze the code, report issues and send pull requests
@eyllanesc, sometimes, I keep more than one project in one repo, ie. ETL-QuranWords or RentManager, and for that, I think, the .zip approach is the best.
Another reason I do this is because I couldn't run my projects (first 2/3 repos) after getting back to windows from linux. I'd uploaded those, with github desktop app, before going to linux from windows.
Later I realised that I've to learn the github technology to upload things and maintain repo properly and also realized that all those learnings will serve no other purpose other than sharing/using code in/from a repo and since my .zip approach serves that purpose very well in a compressed way, I upload .zip.
-
@eyllanesc, sometimes, I keep more than one project in one repo, ie. ETL-QuranWords or RentManager, and for that, I think, the .zip approach is the best.
Another reason I do this is because I couldn't run my projects (first 2/3 repos) after getting back to windows from linux. I'd uploaded those, with github desktop app, before going to linux from windows.
Later I realised that I've to learn the github technology to upload things and maintain repo properly and also realized that all those learnings will serve no other purpose other than sharing/using code in/from a repo and since my .zip approach serves that purpose very well in a compressed way, I upload .zip.
@Emon-Haque Your arguments may or may not be valid, but I thought to help you check the repository but having everything in a zip I get discouraged, bye, hopefully someone will help you.