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. paintEvent() why can't repaint() in QWidget?

paintEvent() why can't repaint() in QWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 635 Views
  • 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.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by
    #1

    0_1521374273720_捕获.PNG

    "save.png" has been added in "images.qrc", its path is ":/save.png".

    After the program runs,

    0_1521374139089_捕获.PNG

    During the program is running, I replaced "save.png" with anthor image (but same name with "save.png") and then click the "save image "button to trigger the left qwidget's repaint() slot, but the left qwidget don't change the background image. Why?

    I don't understand why the qwidget don't change the background. So I try another way.

    In paintEvent(), I replace the path ":/save.png" with "../BaslerWidget/save.png" , and make it, Why it succeed?(but it change the background before I trigger the left qwidget's repaint() , amazing.........)

    Tips: BaslerWidget is my project name. the Build folder and the project folder are in the same level, you can see image below.

    0_1521375172254_捕获.PNG

    beeckscheB 1 Reply Last reply
    0
    • LimerL Limer

      0_1521374273720_捕获.PNG

      "save.png" has been added in "images.qrc", its path is ":/save.png".

      After the program runs,

      0_1521374139089_捕获.PNG

      During the program is running, I replaced "save.png" with anthor image (but same name with "save.png") and then click the "save image "button to trigger the left qwidget's repaint() slot, but the left qwidget don't change the background image. Why?

      I don't understand why the qwidget don't change the background. So I try another way.

      In paintEvent(), I replace the path ":/save.png" with "../BaslerWidget/save.png" , and make it, Why it succeed?(but it change the background before I trigger the left qwidget's repaint() , amazing.........)

      Tips: BaslerWidget is my project name. the Build folder and the project folder are in the same level, you can see image below.

      0_1521375172254_捕获.PNG

      beeckscheB Offline
      beeckscheB Offline
      beecksche
      wrote on last edited by beecksche
      #2

      @Limer

      The image is compiled to the resource file at compile time. So changing at runtime has no effect.

      qmake will produce make rules to generate a file called qrc_application.cpp that is linked into the application. This file contains all the data for the images and other resources as static C++ arrays of compressed binary data. http://doc.qt.io/qt-5/resources.html#compiled-in-resources

      When you replace the path to "../BaslerWidget/save.png" you're not using the Qt resource system, instead you use the path relative to the application.

      1 Reply Last reply
      2
      • LimerL Offline
        LimerL Offline
        Limer
        wrote on last edited by
        #3

        Thanks, I get it.

        1 Reply Last reply
        1

        • Login

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