#include <QtGui>
QString text
= "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " "sed do eiusmod tempor incididunt ut labore et dolore magna "
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
"ullamco laboris nisi ut aliquip ex ea commodo consequat. "
"Duis aute irure dolor in reprehenderit in voluptate velit ...";
{
public:
{
}
{
return QRectF(viewport
()->rect
().
width()-220,
20,
200,
200);
}
{
painter->save();
painter->setWorldMatrixEnabled(false);
painter
->setPen
(QPen(Qt
::darkGray,
2));
painter
->setRenderHint
(QPainter::Antialiasing);
painter
->setBrush
(QColor(0,
0,
0,
10));
painter->drawRoundRect(overlayRect());
painter->drawText(overlayRect().adjusted(20, 20, -20, -20), Qt::TextWordWrap , text);
painter->setWorldMatrixEnabled(true);
painter->restore();
}
void scrollContentsBy(int dx, int dy)
{
// can I force an update here
}
};
int main(int argc, char* argv[])
{
scene.setSceneRect(0,0,2000,2000);
GraphicsView view(&scene);
view.show();
return app.exec();
}
#include <QtGui>
QString text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
"sed do eiusmod tempor incididunt ut labore et dolore magna "
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
"ullamco laboris nisi ut aliquip ex ea commodo consequat. "
"Duis aute irure dolor in reprehenderit in voluptate velit ...";
class GraphicsView : public QGraphicsView
{
public:
GraphicsView(QGraphicsScene* scene)
: QGraphicsView(scene)
{
}
QRectF overlayRect()const
{
return QRectF(viewport()->rect().width()-220, 20, 200, 200);
}
void drawForeground(QPainter *painter, const QRectF &rect)
{
painter->save();
painter->setWorldMatrixEnabled(false);
painter->setPen(QPen(Qt::darkGray, 2));
painter->setRenderHint(QPainter::Antialiasing);
painter->setBrush(QColor(0,0,0,10));
painter->drawRoundRect(overlayRect());
painter->drawText(overlayRect().adjusted(20, 20, -20, -20), Qt::TextWordWrap , text);
painter->setWorldMatrixEnabled(true);
painter->restore();
QGraphicsView::drawForeground(painter, rect);
}
void scrollContentsBy(int dx, int dy)
{
// can I force an update here
QGraphicsView::scrollContentsBy( dx, dy);
}
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(0,0,2000,2000);
GraphicsView view(&scene);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks