Important: Please read the Qt Code of Conduct -

Handling QScrollArea

  • Hi,
    I want to paint a lot of shape via QPainter so I need Scroll to show all of them.
    I make a QScrollArea and must to add a widget to it but I can't handle QPainter where to paint shapes.

    this function draw a line that is too long.
    void MainWindow::paintEvent(QPaintEvent *)
    QPainter painter(this);

    this is the Constructor of mianwindow that I want to handle Scroll:
    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    QScrollArea *area = new QScrollArea();

    so what i should to do in (......) ??!!

    [edit, code tags added, koahnig]

  • Please check out the forum for "writing tags around your code sections.":

    Did you check out already the "image viewer example?": It uses a painter too.

  • i checked it but wasn't useful!

  • Moderators

    [quote author="Hesam4g" date="1379171433"]i checked it but wasn't useful![/quote]
    why wasn't it useful?

    Beside you can use QGraphicsView if you like.

    If you want to stick to the QPainter approach you shouldn't override MainWindow::paintEvent() and do the painting there.Instead you should cretae a simple QWidget subclass, do the painting there and add this widget to the QScrollArea.

Log in to reply