setValue of ScrollBar Don't work at first time
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:
Code:
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());
}
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? :confused:
Thanks in advance!!!!! ;)
Re: setValue of ScrollBar Don't work at first time
It is not very clear in what sequence you are doing the things
Code:
scrollAreaCandidate->horizontalScrollBar()->setValue(2000);
this should done some were after you load the pixmap into QLabel, and set the QLabel in the scroll area, and then set the scroll bar position
Re: setValue of ScrollBar Don't work at first time
That's just what I do, no?
I'll explain: The first eight lines of my code are in the constructor of the class. So, it only be executed once. I call al lot of times to "openImage". The first time I do it not work. And not work only the setValue of the scrollBar, because the resize (MyClass::scaleCandidateImage) works allways.
The following times it works properly.
¿Any ideas?
Re: setValue of ScrollBar Don't work at first time
Ok, try adding this
Code:
scrollAreaCandidate->horizontalScrollBar()->setValue(2000);
scrollAreaCandidate->update(); //Add this
Re: setValue of ScrollBar Don't work at first time
Thanks!!
I had already tested, and didn't works.
I tried:
Code:
scrollAreaCandidate->horizontalScrollBar()->update();
scrollAreaCandidate->update();
scrollAreaCandidate->horizontalScrollBar()->repaint();
But nothing works!!! :(
Re: setValue of ScrollBar Don't work at first time
were in you code you call openImage(), I mean which objects method / slot?
If openImage() is a slot, to which signal is it connected?
Re: setValue of ScrollBar Don't work at first time
Thanks for reply!
The connexions are very sophisticated. MyClass emits a signal when is clicked a button. I connect this signal with another slot of other class (MainWindow). MainWindow do some operations and generates a string (path). I emit a signal with this string, and the receiver is MyClass::openImage.
At fisrt time, mainWindow emits the signal with a default path. Perhaps the error could be there. But I can't understand why the first time it scale the image properly and not set the value of the scrollBar! :confused:
Re: setValue of ScrollBar Don't work at first time
try to use: QScrollArea::alignment-prop I think this is what you really want.
Re: setValue of ScrollBar Don't work at first time
Quote:
Originally Posted by
MarekR22
I read that this is to centre (for example) the content. http://lists.trolltech.com/qt4-previ...ad00063-0.html
Maybe my poor english is confusing. My apologies. Anyway, I tried and it didn't work.
I simplified the code to show you. The "2000", actually, is a variable that contains a different value called pointX. Point is calculated every time I load an image, before the setValue. It contain the correct number in each image, but it didn't set the value to the crolBar...
Thank you very much!! :D