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]
↧