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

_h_ hiralsmaillist at gmail.com
Mon Aug 24 15:26:59 CEST 2009


Hi John,

> If the scene is larger than the view's viewport, the view displays
scrollbars.
As I am drawing text using QPainter it is not resizing the QGraphicsView,
 but if I use the QGraphicsTextItem the view gets resize accordingly.

> You re> placed the viewport with a QGLWidget. QGLWidgets don't resize when
drawing goes past the borders so the view doesn't display scrollbars.

No I am not using QGLWidget as viewport.

> You can try manually resizing the viewport to accomodate the text.

Any suggestion.

Thank you.


On Fri, Aug 21, 2009 at 10:39 PM, John McClurkin <jwm at nei.nih.gov> wrote:

>  _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.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090824/9b94c642/attachment.html 


More information about the Qt-interest-old mailing list