Results 1 to 7 of 7

Thread: Pixmap do not getting set in label

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Pixmap do not getting set in label

    Hi

    Might be this question i should not ask but i am not understanding what is wrong with this. I am trying to set a pixmap to a label (here label is my custom label class in which i inherit paintEvent() and mousePressEvent()) , but it is not getting display. I checked whether image is loaded or not , i found that image is loaded correctly.
    My code for setting pixmap is


    QPixmap image1(":/buttonn.png");
    this.setPixmap(QPixmap::fromImage(image1));
    if(image1.isNull()){
    label->setText("null pic");
    }

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Pixmap do not getting set in label

    Quote Originally Posted by Niamita View Post
    QPixmap image1(":/buttonn.png");
    this.setPixmap(QPixmap::fromImage(image1));
    ? image1 is already a pixmap. So simple use
    Qt Code:
    1. this.setPixmap(image1);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Pixmap do not getting set in label

    thank you Lykurg for immediate response, but i am still not successful in setting pixmap to label.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Pixmap do not getting set in label

    Then please post a little bit more code or even better, make a compilable example reproducing your problem. Because the error seems not to be in your posted code.

  5. #5
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Pixmap do not getting set in label

    Ok
    i have a class in which i make instance of my custom label class.
    In my custom label claas i am trying to set pixmap in my class constructor with above posted code. i override paintEvent() and mousePressEvent() method only in that class excepting setting pixmap.
    I am not getting what i am doing wrong.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Pixmap do not getting set in label

    how does the paintEvent() looks like? Maybe you simply do not draw the pixmap? This works normaly fine:
    Qt Code:
    1. class MyLabel : public QLabel
    2. {
    3. Q_OBJECT
    4. MyLabel(...)
    5. {
    6. setPixmap("...")
    7. }
    8. };
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Pixmap do not getting set in label

    i solved the problem by setting a label as its child.
    well thanks Lykurg for responsing.
    Thank you.

Similar Threads

  1. Change the size of pixmap in a label
    By metRo_ in forum Qt Programming
    Replies: 16
    Last Post: 1st June 2012, 10:21
  2. Replies: 1
    Last Post: 19th April 2011, 11:17
  3. [Qt 4.6.3] : pixmap resource for a label
    By didier in forum Qt Programming
    Replies: 10
    Last Post: 17th September 2010, 01:02
  4. label - pixmap - problem
    By qwrhiobasdbgghoasdf in forum Newbie
    Replies: 5
    Last Post: 16th September 2010, 00:29
  5. How do i change images? Qt creator label>pixmap
    By QueenZ in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2010, 04:44

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.