Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. HELP! I want to zoomIn and zoomOut scribble area.

HELP! I want to zoomIn and zoomOut scribble area.

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.8k 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.
  • N Offline
    N Offline
    NandiniN
    wrote on last edited by
    #1

    I am trying to zoomIn And zoomOut the scribble area or paint area..by the following code ,On opening the image and painting on it works fine,but when i try to zoom (view->zoomIn25%) i can zoom only the image,what i had scribbled gets disappeared..why can't i draw on widget? Please help me with the CODE to zoom the scribbleArea along with the image!!

    I have
    main.cpp
    mainwindow.cpp
    scribblearea.cpp along with the header files.

    MAINWINDOW.CPP

    @MainWindow::MainWindow()
    {
    imageLabel = new QLabel;
    scribbleArea = new ScribbleArea;
    setCentralWidget(scribbleArea);
    imageLabel->setBackgroundRole(QPalette::Base);
    imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    imageLabel->setScaledContents(true);

    scrollArea = new QScrollArea;
    

    scrollArea->setBackgroundRole(QPalette::Dark);
    scrollArea->setWidget(imageLabel);

    createActions();
    createMenus();
    
    setWindowTitle(tr("Scribble"));
    resize(500, 400);
    

    }

    void MainWindow::open()
    {

    if (maybeSave()) {
    QString fileName = QFileDialog::getOpenFileName(this,
    tr("Open File"), QDir::currentPath());
    if (!fileName.isEmpty()) {
    scribbleArea->openImage(fileName);
    QImage image(fileName);
    imageLabel->setPixmap(QPixmap::fromImage(image));

        scaleFactor = 1.0;
    
        printAct->setEnabled(true);
        fitToWindowAct->setEnabled(true);
        updateActions();
    
        if (!fitToWindowAct->isChecked())
            imageLabel->adjustSize();
    }
    
    }
    

    }
    void MainWindow::zoomIn()

    {

    scaleImage(1.25);//"got these from":http://qt-project.org/doc/qt-4.8/widgets-imageviewer-imageviewer-cpp.html
    

    }
    void MainWindow::zoomOut()

    {
    scaleImage(0.8);
    }
    void MainWindow::createActions()

    {

    }
    void MainWindow::createMenus()
    //! [15] //! [16]
    {

    --
    }
    void MainWindow::scaleImage(double factor)

    {
    setCentralWidget(scrollArea);
    //setCentralWidget(scribbleArea);
    Q_ASSERT(imageLabel->pixmap());
    scaleFactor *= factor;
    imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());

    adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
    

    adjustScrollBar(scrollArea->verticalScrollBar(), factor);

    zoomInAct->setEnabled(scaleFactor < 3.0);
    zoomOutAct->setEnabled(scaleFactor > 0.333);
    

    }
    void MainWindow::adjustScrollBar(QScrollBar *scrollBar, double factor)
    //! [25] //! [26]
    {

    }
    void MainWindow::fitToWindow()
    {

     }
     updateActions();
    

    }
    void MainWindow::normalSize()
    {

    }
    void MainWindow::updateActions()
    {

    }@

    SCRIBBLEAREA.CPP
    "have made no changes to this...":http://http://qt-project.org/doc/qt-4.8/widgets-scribble-scribblearea-cpp.html

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DoctorAgony
      wrote on last edited by
      #2

      Hi there,

      first: try to use this in a QGraphicsview. It's a little bit easier, and, you can zoom the complete view with all layers in the QGraphicsView.

      For this, you have to create a QGraphicsScene, where you can put a lot of QGraphicItems (doesn't matter if pictures or self created items). And than you can show it in the view.

      second: you don't have to use it, like in the example. Use "scale()", when you use the GraphicsView.

      third: Use fractional numbers for the scaling values. It's more accurate.

      Ding! - What is that?! - It's a machine, that goes DING!

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NandiniN
        wrote on last edited by
        #3

        i was trying to add zoomIn and zoomOut to Qt diagramscene example ..

        added
        void MainWindow::mouseMoveEvent(QMouseEvent *event)
        {
        }
        void MainWindow::mouseReleaseEvent(QMouseEvent *event)
        {
        }
        void MainWindow::paintEvent(QPaintEvent *event)
        {
        }
        void MainWindow::resizeEvent(QResizeEvent *event)
        {
        }
        void MainWindow::resizeImage(QImage *image, const QSize &newSize)
        {
        }
        void MainWindow::drawLineTo(const QPoint &endPoint)
        {
        }

        Still No errors nor No desired output... How to draw/paint in that already present drag and drop area.

        I am implementing a paint application for now i want file->open image and
        scribble on that and Zoom the complete thing.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DoctorAgony
          wrote on last edited by
          #4

          Is there any code implemented?

          Ding! - What is that?! - It's a machine, that goes DING!

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NandiniN
            wrote on last edited by
            #5

            the complete diagramscene example here-

            http://harmattan-dev.nokia.com/docs/library/html/qt4/graphicsview-diagramscene.html

            i tried inserting the below mentioned functions into "mainwindow.cpp" of diagramscene ..
            @
            void MainWindow::mousePressEvent(QMouseEvent *event)
            {
            if (event->button() == Qt::LeftButton) {
            lastPoint = event->pos();
            scribbling = true;
            }
            }

            void MainWindow::mouseMoveEvent(QMouseEvent *event)
            {
            if ((event->buttons() & Qt::LeftButton) && scribbling)
            drawLineTo(event->pos());
            }

            void ScribbleArea::mouseReleaseEvent(QMouseEvent *event)
            {
            if (event->button() == Qt::LeftButton && scribbling) {
            drawLineTo(event->pos());
            scribbling = false;
            }
            }

            void MainWindow::paintEvent(QPaintEvent *event)
            {
            QPainter painter(this);
            QRect dirtyRect = event->rect();
            painter.drawImage(dirtyRect, image, dirtyRect);
            }

            void MainWindow::resizeEvent(QResizeEvent *event)
            {
            if (width() > image.width() || height() > image.height()) {
            int newWidth = qMax(width() + 128, image.width());
            int newHeight = qMax(height() + 128, image.height());
            resizeImage(&image, QSize(newWidth, newHeight));
            update();
            }
            QWidget::resizeEvent(event);
            }

            void MainWindow::drawLineTo(const QPoint &endPoint)
            {
            QPainter painter(&image);
            painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
            Qt::RoundJoin));
            painter.drawLine(lastPoint, endPoint);
            modified = true;

             int rad = (myPenWidth / 2) + 2;
             update(QRect(lastPoint, endPoint).normalized()
                                              .adjusted(-rad, -rad, +rad, +rad));
             lastPoint = endPoint;
            

            }

            void MainWindow::resizeImage(QImage *image, const QSize &newSize)
            {
            if (image->size() == newSize)
            return;

             QImage newImage(newSize, QImage::Format_RGB32);
             newImage.fill(qRgb(255, 255, 255));
             QPainter painter(&newImage);
             painter.drawImage(QPoint(0, 0), *image);
             *image = newImage;
            

            }@

            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