×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Question problem with showing pixmap in a label

    hi,
    i am facing prblem with loading pixmap to a label, the images is taken from my device through QFileDialog...when i choose an image and try to insert it to the label , it is not always showing..sometimes it appears as black image
    note that for small pictures(<300 or 400 kb) it is working always without problem

    i am using the following

    QString fileName = QFileDialog::getOpenFileName(this,tr("Select Contact Picture"), ".", tr("Image Files (*.png *.jpg *.bmp)"));

    if (!fileName.isEmpty())
    {
    m_newAvatarPath = fileName;
    m_thumbnail = QImage(m_newAvatarPath);
    if (m_thumbnail.isNull())
    {
    QMessageBox::information(this,"Error","Cannot load the image");
    }
    else{
    QPixmap pixx= QPixmap::fromImage(m_thumbnail);
    ui->label->clear();
    ui->label->setPixmap(pixx.scaled(ui->label->size()));
    }
    ui->label->show();
    ui->label->setScaledContents(true);
    can anyone help me telling me what is wrong with this code??
    sometimes the image shows in the label correctly and sometimes it appears as black one
    Thank you
    Rondo

  2. #2
    Registered User
    Join Date
    Jan 2011
    Posts
    192

    Re: problem with showing pixmap in a label

    Quote Originally Posted by Rondo23 View Post
    hi,
    i am facing prblem with loading pixmap to a label, the images is taken from my device through QFileDialog...when i choose an image and try to insert it to the label , it is not always showing..sometimes it appears as black image
    note that for small pictures(<300 or 400 kb) it is working always without problem

    i am using the following



    can anyone help me telling me what is wrong with this code??
    sometimes the image shows in the label correctly and sometimes it appears as black one
    Thank you
    Rondo
    You must use QImageReader
    search the wiki and the docs how to use it, and good luck

  3. #3
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: problem with showing pixmap in a label

    Quote Originally Posted by lipos123 View Post
    You must use QImageReader
    search the wiki and the docs how to use it, and good luck
    Thank you lipos..
    QImageReader solved the problem
    Best Regards
    Rondo

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: problem with showing pixmap in a label

    Black images are a clue that you're running out of heap. If you load a large image and then "thumbnail" it, it still takes up as much space as the large image (which is often ten times more than the image file). QImageReader is "smart" and knows how to read an image into a smaller version without consuming lots of storage.

Similar Threads

  1. Autoresize of label with pixmap
    By Nocia in forum Qt
    Replies: 4
    Last Post: 2010-10-28, 17:02
  2. not showing full text in the Label of the textfiled in A form
    By kumar.modi in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2010-01-23, 12:45
  3. problem with displaying label in view..........
    By platinnum in forum Symbian
    Replies: 1
    Last Post: 2005-04-25, 04:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •