Results 1 to 9 of 9

Thread: setValue of ScrollBar Don't work at first time

  1. #1
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question 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:

    Qt Code:
    1. imageLabelCandidate = new QLabel();
    2. imageLabelCandidate->setBackgroundRole(QPalette::Base);
    3. imageLabelCandidate->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    4. imageLabelCandidate->setScaledContents(true);
    5.  
    6. scrollAreaCandidate = new QScrollArea;
    7. scrollAreaCandidate->setBackgroundRole(QPalette::Dark);
    8. scrollAreaCandidate->setWidget(imageLabelCandidate);
    9.  
    10. void MyClass::openImage(string *path){
    11. QString fileName = QString::fromStdString(*path);
    12. if (!fileName.isEmpty()) {
    13. QImage image(fileName);
    14. if (image.isNull()) {
    15. cout << "ERROR opening file" << endl;
    16. return;
    17. }
    18. imageLabelCandidate->setPixmap(QPixmap::fromImage(image));
    19. imageLabelCandidate->MPixmap(QPixmap::fromImage(image));
    20. imageLabelCandidate->adjustSize();
    21. scaleCandidateImage(1.3);
    22. scrollAreaCandidate->horizontalScrollBar()->setValue(2000);
    23. }
    24.  
    25. void MyClass::scaleCandidateImage(double factor)
    26. {
    27. Q_ASSERT(imageLabelCandidate->pixmap());
    28. imageLabelCandidate->resize(factor * imageLabelCandidate->pixmap()->size());
    29. }
    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!!!!!
    Last edited by sergio87; 7th June 2011 at 12:10.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: setValue of ScrollBar Don't work at first time

    It is not very clear in what sequence you are doing the things
    Qt Code:
    1. scrollAreaCandidate->horizontalScrollBar()->setValue(2000);
    To copy to clipboard, switch view to plain text mode 
    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

  3. #3
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default 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?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: setValue of ScrollBar Don't work at first time

    Ok, try adding this
    Qt Code:
    1. scrollAreaCandidate->horizontalScrollBar()->setValue(2000);
    2. scrollAreaCandidate->update(); //Add this
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Santosh Reddy for this useful post:

    sergio87 (8th June 2011)

  6. #5
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: setValue of ScrollBar Don't work at first time

    Thanks!!
    I had already tested, and didn't works.

    I tried:
    Qt Code:
    1. scrollAreaCandidate->horizontalScrollBar()->update();
    2. scrollAreaCandidate->update();
    3. scrollAreaCandidate->horizontalScrollBar()->repaint();
    To copy to clipboard, switch view to plain text mode 

    But nothing works!!!

  7. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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?

  8. #7
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default 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:penImage.

    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!

  9. #8
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setValue of ScrollBar Don't work at first time

    try to use: QScrollArea::alignment-prop I think this is what you really want.

  10. The following user says thank you to MarekR22 for this useful post:

    sergio87 (8th June 2011)

  11. #9
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: setValue of ScrollBar Don't work at first time

    Quote Originally Posted by MarekR22 View Post
    try to use: QScrollArea::alignment-prop I think this is what you really want.
    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!!
    Last edited by sergio87; 8th June 2011 at 11:06.

Similar Threads

  1. Replies: 0
    Last Post: 12th August 2010, 16:05
  2. How to use setValue in QSqlTableModel?
    By jtdavidson in forum Newbie
    Replies: 1
    Last Post: 21st July 2010, 15:10
  3. qsettings setvalue has something unnecessary
    By yj_yulin in forum Qt Programming
    Replies: 2
    Last Post: 14th June 2010, 05:46
  4. SetValue
    By phillip_Qt in forum Qt Programming
    Replies: 4
    Last Post: 3rd October 2007, 22:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.