Results 1 to 12 of 12

Thread: Pixmap updating QLabel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Pixmap updating QLabel

    I am new to Qt as of yesterday, and I was hoping someone would be able to help me with a problem. I am writing a program to act like XKCD, but I can't get pixmap to update label. Here is a section, I will attach the full files in case they would help.

    Qt Code:
    1. int val = 1;
    2. XKCD::XKCD(QWidget *parent)
    3. : QWidget(parent)
    4. {
    5. QString number;
    6. QString png = ".png";
    7. QString pics = "pics/";
    8. number.setNum(val);
    9. number.prepend(pics);
    10. number.append(png);
    11.  
    12. QPixmap *original=new QPixmap(QString(number));
    13. QPixmap image(original->scaled ( 1300,700, Qt::KeepAspectRatio, Qt::SmoothTransformation ));
    14. QLabel *label = new QLabel(this);
    15. label->setPixmap(image);
    16. int pixwidth = image.width();
    17. int labelwidth = (WIDTH - pixwidth) / 2;
    18. label->setGeometry(labelwidth, SIZEY, pixwidth, 700);
    19. }
    20.  
    21. void XKCD::OnPrev()
    22. {
    23. val--;
    24. if (val < 1) {val = 0;}
    25. QString number;
    26. QString png = ".png";
    27. QString pics = "pics/";
    28. number = number.setNum(val);
    29. number = number.prepend(pics);
    30. number = number.append(png);
    31. QPixmap *original=new QPixmap(QString(number));
    32. QPixmap image= (original->scaled ( 1300, 600, Qt::KeepAspectRatio, Qt::SmoothTransformation ));
    33. QLabel *label = new QLabel(this);
    34. label->setPixmap(image);
    35. int pixwidth = image.width();
    36. int labelwidth = (WIDTH - pixwidth) / 2;
    37. label->setGeometry(labelwidth, SIZEY, pixwidth, 700);
    38. /* Debugging purposes */ std::cout << "Val is now: "<< val << ". The image path is now: " << number.toStdString() << "." << std::endl;
    39. }
    To copy to clipboard, switch view to plain text mode 

    Hopefully someone can help me, I haven't found anything in documentation yet. Thanks for looking at my problem.

    Attached are my project files.
    xkcd.cpp
    xkcd.h
    main.cpp

    Edit: If it would be possible or easier to do using QImage, I am certainly open to that if someone could help me with it. My attempt to switch from QPixmap to QImage gave me a mile long set of errors that I couldn't find a workaround for.
    Last edited by Matt; 17th August 2010 at 18:50.

Similar Threads

  1. DB changes not updating in views
    By Jeffb in forum Newbie
    Replies: 11
    Last Post: 11th May 2010, 10:00
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Updating from Qt-4.4.3 to Qt-4.5.0 --Help Needed
    By swamyonline in forum Installation and Deployment
    Replies: 1
    Last Post: 9th February 2009, 11:37
  4. Replies: 1
    Last Post: 2nd August 2008, 15:46
  5. empty pixmap as a QLabel
    By tommy in forum Qt Programming
    Replies: 16
    Last Post: 11th December 2007, 21:15

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.