Results 1 to 3 of 3

Thread: display QImage on QLabel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default display QImage on QLabel

    Hi! I am trying to display image on the label:

    Creating the image:

    Qt Code:
    1. static const QRgb s_rgnColors[256] =
    2. {
    3. (unsigned int)0x000000,
    4. (unsigned int)0xFF0000,
    5. (unsigned int)0x00FF00,
    6. (unsigned int)0xFFFF00,
    7. (unsigned int)0x0000FF,
    8. (unsigned int)0xFF00FF,
    9. (unsigned int)0x00FFFF,
    10. (unsigned int)0xFFFFFF,
    11.  
    12. // TODO: think about other colors
    13. (unsigned int)0x000000
    14.  
    15. };
    16.  
    17. QImage *m_imageFloor = new QImage(nWidth, nHeight, QImage::Format_Indexed8);
    18. m_imageFloor->setColorTable(QVector<QRgb>::fromStdVector(
    19. std::vector<QRgb>(s_rgnColors, s_rgnColors + _countof(s_rgnColors)))
    20. );
    21. m_imageFloor->fill(7);
    To copy to clipboard, switch view to plain text mode 

    and showing it on the label

    Qt Code:
    1. m_labelFloorPlan = new QLabel();
    2. m_labelFloorPlan->setSizePolicy(QSizePolicy::Expanding,
    3. QSizePolicy::Expanding);
    4. m_labelFloorPlan->setAlignment(Qt::AlignCenter);
    5. m_labelFloorPlan->setMinimumSize(400, 400);
    6. m_labelFloorPlan->setPixmap(QPixmap::fromImage(*m_imageFloor, Qt::AutoColor));
    7. setCentralWidget(m_labelFloorPlan);
    To copy to clipboard, switch view to plain text mode 

    But the image does not appear
    What am I doing wrong??

    Thank you.
    Last edited by jpn; 23rd September 2008 at 15:33. Reason: missing [code] tags

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. Replies: 3
    Last Post: 17th July 2008, 07:43
  3. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 14:50
  4. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  5. QShared
    By sabeesh in forum Qt Programming
    Replies: 11
    Last Post: 11th October 2007, 12:40

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.