[Qt-interest] How to scroll text drawn with Qpainter in QGraphicsview

John McClurkin jwm at nei.nih.gov
Fri Aug 21 19:09:24 CEST 2009


_h_ wrote:
> Hi,
>  
> I have implemented QGraphicsView as follow...
>  
>   3 class GraphicsView: public QGraphicsView
>   4 {
>   5     public:
>   6         GraphicsView(QGraphicsScene *s): QGraphicsView(s) {};
>   7
>   8         GraphicsView(QWidget *parent): QGraphicsView(parent) {
>   9             //setViewport(new QGLWidget);
>  10             //setViewportUpdateMode(FullViewPortUpdate);
>  11             //setOptimizationFlags(DontClipPainter);
>  12             //setCacheMode(CacheNone);
>  13         };
>  14         ~GraphicsView(){};
>  15     protected:
>  16         /*void drawBackground(QPainter *painter, const QRectF &rect) {
>  17             //painter->save();
>  18             //paintGL();
>  19             //painter->restore();
>  20             //painter->fillRect(rect, Qt::blue);
>  21         }*/
>  22         void drawForeground(QPainter *painter, const QRectF &rect) {
>  23             QColor c(0, 255, 127);
>  24             painter->fillRect(rect, c);
>  25             QFont f;
>  26             f.setPointSize(25);
>  27             painter->setFont(f);
>  28             painter->drawText(0,0, "help would required to scoll 
> this text");
>  29         }
>  30 };
> The problem here is that the text drawn with painter (at line 28) is 
> getting cut and QGraphicsView doesn't shows the scrollbars.
>  
> In my application user can set any font size, and based on the font size 
> view should display scrollbars.
>  
> Thank you in advance.
>  
> Thank you.
A QGraphicsView object is usually used to show a QGraphicsScene object. 
If the scene is larger than the view's viewport, the view displays 
scrollbars. You replaced the viewport with a QGLWidget. QGLWidgets don't 
resize when drawing goes past the borders so the view doesn't display 
scrollbars. You can try manually resizing the viewport to accomodate the 
text.



More information about the Qt-interest-old mailing list