Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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);
    painter.setPen(Qt::blue);
    painter.drawLine(30,30,30,300);
    painter.drawLine(30,300,3000000,300);
    }
    @

    this is the Constructor of mianwindow that I want to handle Scroll:
    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    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.":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01

    Did you check out already the "image viewer example?":http://qt-project.org/doc/qt-5.0/qtwidgets/widgets-imageviewer.html 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