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. the icon.jpg how loaded in Qt Creator ? I have to create image folder?
Forum Updated to NodeBB v4.3 + New Features

the icon.jpg how loaded in Qt Creator ? I have to create image folder?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.2k 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.
  • L Offline
    L Offline
    lse123
    wrote on last edited by
    #1

    code like this for alert boxes with image
    QPixmap myIcon(":/images/icon.jpg"); //
    the icon.jpg how loaded in Qt Creator ? I have to create image folder?

    QMessageBox msgBox2;
     msgBox2.setWindowTitle("Serious Question");
     msgBox2.setText("Am I an awesome guy?");
     msgBox2.addButton("Seriously Yes!", QMessageBox::YesRole);
     msgBox2.addButton("Seriously No!", QMessageBox::NoRole);
     QPixmap myIcon(":/images/icon.jpg");
     msgBox2.setIconPixmap(myIcon);
     msgBox2.setIcon(QMessageBox::Question);
     msgBox2.exec();
    
    sierdzioS 1 Reply Last reply
    0
    • L lse123

      code like this for alert boxes with image
      QPixmap myIcon(":/images/icon.jpg"); //
      the icon.jpg how loaded in Qt Creator ? I have to create image folder?

      QMessageBox msgBox2;
       msgBox2.setWindowTitle("Serious Question");
       msgBox2.setText("Am I an awesome guy?");
       msgBox2.addButton("Seriously Yes!", QMessageBox::YesRole);
       msgBox2.addButton("Seriously No!", QMessageBox::NoRole);
       QPixmap myIcon(":/images/icon.jpg");
       msgBox2.setIconPixmap(myIcon);
       msgBox2.setIcon(QMessageBox::Question);
       msgBox2.exec();
      
      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:

      the icon.jpg how loaded in Qt Creator ? I have to create image folder?

      Can you explain it in different words? I have no idea what you mean.

      I'll give a general answer, it may not apply to your case:

      The :/ notation us used for Qt Resources, you can read all about them here.

      Normally, if you have a filesystem structure like:

      SomeDirectory
       |
       *- yourResourceFile.qrc
       |
       *- images
            |
           * icon.jpg
      

      and you just add your icon to QRC via Qt Creator's editor - then your path to that file will indeed become :/images/icon.jpg. But the power of QRC system is that you can create any directory structure you like, add prefixes, aliases etc. So a really accurate answer to I have to create image folder? is depends ;-)

      (Z(:^

      1 Reply Last reply
      3
      • L Offline
        L Offline
        lse123
        wrote on last edited by
        #3

        @lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:

        QPixmap myIcon(":/images/icon.jpg");

        this ebook chapter about message dialog windows/alerts
        says this QPixmap myIcon(":/images/icon.jpg");
        but Not say how put image or create resource file ... so you mean use this https://doc.qt.io/qt-5/resources.html ... ?

        jsulmJ 1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Yes, use the docs. It's really easy, don't worry. For your use case you just need to add a resource file and one entry inside it. You can do it manually (like in the documentation) or using Qt Creator to help you.

          (Z(:^

          1 Reply Last reply
          1
          • L lse123

            @lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:

            QPixmap myIcon(":/images/icon.jpg");

            this ebook chapter about message dialog windows/alerts
            says this QPixmap myIcon(":/images/icon.jpg");
            but Not say how put image or create resource file ... so you mean use this https://doc.qt.io/qt-5/resources.html ... ?

            jsulmJ Online
            jsulmJ Online
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:

            this ebook

            Which ebook do you mean? My guess is that the resource system is explained somewhere else in that book.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lse123
              wrote on last edited by lse123
              #6

              @lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:

              QPixmap myIcon(":/images/icon.jpg");
              msgBox2.setIconPixmap(myIcon);
              msgBox2.setIcon(QMessageBox::Question);
              msgBox2.exec();

              The problem was and solve it is must comment the line in BOLD below because overwrites the seticonPixmap with "?" question icon...

              msgBox2.setIconPixmap(myIcon);
              > msgBox2.setIcon(QMessageBox::Question);

              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