Results 1 to 9 of 9

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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
  •  
Qt is a trademark of The Qt Company.