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 drawing a QPixmap on screen with a QPainter
Forum Updated to NodeBB v4.3 + New Features

Problem drawing a QPixmap on screen with a QPainter

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.9k 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.
  • P Offline
    P Offline
    Psycho_Path
    wrote on 10 Mar 2012, 21:49 last edited by
    #1

    So my code basically looks like this (where the code is placed in the constructor of a class that inherits from QWidget)

    @
    QPainter p(this);
    QPixmap temp;
    QString fileName = "folder/art.png";
    if (temp.load(fileName) == false)
    {
    QMessageBox mb(this);
    QString qs("Failed to load " + fileName);
    mb.setText(qs);
    mb.exec();
    } else {
    QMessageBox mb(this);
    QString qs("Loaded image " + fileName);
    mb.setText(qs);
    mb.exec();
    }
    p.drawPixmap(200, 200, temp);
    @

    The image loaded fine but won't draw on the screen. Have also tried using the repaint() method after the call to p.drawPixmap(...);

    Any help would be much appreciated,

    Thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 10 Mar 2012, 21:54 last edited by
      #2

      To draw on a widget with your own code, you must reimplement "QWidget::paintEvent() ":/doc/qt-4.8/qwidget.html#paintEvent. You cannot draw in the constructor of a widget.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Psycho_Path
        wrote on 10 Mar 2012, 23:38 last edited by
        #3

        Thanks for the quick response. This is indeed my problem here.

        1 Reply Last reply
        0

        3/3

        10 Mar 2012, 23:38

        • Login

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