Hi!
I open an image in a QLabel as a QPixmap. When I opened the image I resize it. Then I "center" the image respect to a particular pixel. "Center" the image is to set value to the ScrollBar. The code is:
imageLabelCandidate
= new QLabel();
imageLabelCandidate
->setBackgroundRole
(QPalette::Base);
imageLabelCandidate->setScaledContents(true);
scrollAreaCandidate
->setBackgroundRole
(QPalette::Dark);
scrollAreaCandidate->setWidget(imageLabelCandidate);
void MyClass::openImage(string *path){
if (!fileName.isEmpty()) {
if (image.isNull()) {
cout << "ERROR opening file" << endl;
return;
}
imageLabelCandidate
->setPixmap
(QPixmap::fromImage(image
));
imageLabelCandidate
->MPixmap
(QPixmap::fromImage(image
));
imageLabelCandidate->adjustSize();
scaleCandidateImage(1.3);
scrollAreaCandidate->horizontalScrollBar()->setValue(2000);
}
void MyClass::scaleCandidateImage(double factor)
{
Q_ASSERT(imageLabelCandidate->pixmap());
imageLabelCandidate->resize(factor * imageLabelCandidate->pixmap()->size());
}
imageLabelCandidate = new QLabel();
imageLabelCandidate->setBackgroundRole(QPalette::Base);
imageLabelCandidate->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabelCandidate->setScaledContents(true);
scrollAreaCandidate = new QScrollArea;
scrollAreaCandidate->setBackgroundRole(QPalette::Dark);
scrollAreaCandidate->setWidget(imageLabelCandidate);
void MyClass::openImage(string *path){
QString fileName = QString::fromStdString(*path);
if (!fileName.isEmpty()) {
QImage image(fileName);
if (image.isNull()) {
cout << "ERROR opening file" << endl;
return;
}
imageLabelCandidate->setPixmap(QPixmap::fromImage(image));
imageLabelCandidate->MPixmap(QPixmap::fromImage(image));
imageLabelCandidate->adjustSize();
scaleCandidateImage(1.3);
scrollAreaCandidate->horizontalScrollBar()->setValue(2000);
}
void MyClass::scaleCandidateImage(double factor)
{
Q_ASSERT(imageLabelCandidate->pixmap());
imageLabelCandidate->resize(factor * imageLabelCandidate->pixmap()->size());
}
To copy to clipboard, switch view to plain text mode
The problem is that the first time I call "openImage" it don't set the value 2000 to the horizontalScrollBar. The following times it works properly.
Where I make the mistake?
Thanks in advance!!!!!
Bookmarks