Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem Using QLabel::paintEvent to Draw an Image
Forum Updated to NodeBB v4.3 + New Features

Problem Using QLabel::paintEvent to Draw an Image

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    allenpm
    wrote on last edited by
    #1

    I need to draw an image that is formatted as a "TCL" file and must be displayed using a function in a TCL library named TCL_Display. TCL_Display requires an HDC object to be provided, and it draws the image onto that device context.

    In order to accomplish this in a QLabel window, I am overriding the paintEvent function as shown below (my NavChartImgWnd class is derived from QLabel). Note that mChartId will be zero until an image has been loaded (by another function in the TCL library), so the paintEvent function will not do anything until an image has been loaded and mChartId has been set to a valid chart ID that TCL_Display can operate on.

    @
    void NavChartImgWnd::paintEvent(QPaintEvent * event)
    {
    if( mChartId == 0) return;

    HDC      lWndDC = getDC();
    
    TCL_Display( mChartId, hDC, 1.0, 1.0, NULL, NULL, 0);
    

    releaseDC(lWndDC);
    }
    @

    The result I get when I execute this code is that the image appears momentarily in the window and then disappears. I can get the image to appear and persist by moving the scroll bar (the NavChartImgWnd object is placed inside a QScrollWindow object using setWidget), but it disappears whenever focus is shifted to another window and does not reappear until I once again move the scroll bar. By setting a break point after the call to TCL_Display, I can verify that paintEvent is being called when focus is returned to the window, and the image appears on the screen immediately after the call to TCL_Display, but it is erased after leaving paintEvent.

    Can anyone tell me what I'm doing wrong? I am new to Qt, so I'm probably making some very fundamental errors.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved