Originally Posted by
Lykurg
Instead of setting the transformation to each item you use and in your particular case, it's better to create your own item and draw the text yourself:
In paint also draw the text via
QPainter::drawText() (there are alignment flags) and then rotate the painter by 90°. And don't forget to implement the sizeHint() function.
QPainter will be the best solution when the rect area is smallest than the text, but if I try to create a QPainter object for that QGraphicsScene as the following code:
for (int i = 0; i < 12; i++)
{
// mese->setPen(QPen(Qt::red, 1, Qt::SolidLine));
mese->setPen(Qt::NoPen);
mese->setBrush(Qt::NoBrush);
painter.drawText(mese, Qt::AlignCenter, mesiAnno.at(i));
painter.drawRect(mese);
QGraphicsScene *scene =
new QGraphicsScene(QRect(0, 0, endX, endY), this);
for (int i = 0; i < 12; i++)
{
QGraphicsRectItem *mese =
new QGraphicsRectItem(QRect(margineX + 2 + 60 * i, endY - margineY + 2, 60, 30), 0, scene);
// mese->setPen(QPen(Qt::red, 1, Qt::SolidLine));
mese->setPen(Qt::NoPen);
mese->setBrush(Qt::NoBrush);
QPainter painter(scene);
painter.drawText(mese, Qt::AlignCenter, mesiAnno.at(i));
painter.drawRect(mese);
To copy to clipboard, switch view to plain text mode
the compiler is not agree with me because:
note: candidates are: QPainter::QPainter(const QPainter&)
note: QPainter::QPainter(QPaintDevice*)
error: no matching function for call to `QPainter::QPainter(QGraphicsScene*&)'
note: candidates are: QPainter::QPainter(const QPainter&)
note: QPainter::QPainter(QPaintDevice*)
To copy to clipboard, switch view to plain text mode
where do i have to link my QPainter object???
thanks guys, I really appreciate your comments!
Bookmarks