Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Handling QScrollArea
Forum Updated to NodeBB v4.3 + New Features

Handling QScrollArea

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hesam4g
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hesam4g
        wrote on last edited by
        #3

        i checked it but wasn't useful!

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          [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.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved