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. path for image Label
Qt 6.11 is out! See what's new in the release blog

path for image Label

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

    Hello,
    I need to tp image Label
    If I use
    QPixmap pix("E:/work/QTProgz/logo.jpg");
    ui->imagelabel->setPixmap(pix);
    ui->imagelabel->setScaledContents(true);

    It's showing
    But if i dont know directory

    QString imageFileName;
    imageFileName=(QDir::currentPath()).append("/logo.jpg");
    QPixmap pix(imageFileName);
    ui->imagelabel->setPixmap(pix);
    ui->imagelabel->setScaledContents(true);

    it's not showing

    So how to fix it ?

    Thanks

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      The best way to fix is to use resource.
      as absolute path will break as soon it sees a new pc.
      http://doc.qt.io/qt-5/resources.html

      http://www.bogotobogo.com/Qt/Qt5_Resource_Files.php
      ps no need to add Add Prefix.

      1 Reply Last reply
      2
      • V Offline
        V Offline
        Vics
        wrote on last edited by
        #3

        Thank you for your reply

        but i'm working under Qt 4.7

        I'm not sure that it supports resources

        mrjjM 1 Reply Last reply
        0
        • V Vics

          Thank you for your reply

          but i'm working under Qt 4.7

          I'm not sure that it supports resources

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Vics
          The menus are not there in Creator ?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vics
            wrote on last edited by
            #5

            There are no resources in menus in Creator
            I havent anything like showing there http://www.bogotobogo.com/Qt/Qt5_Resource_Files.php

            P.S. my logo jpg file holds in the same dir, where holds the application.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              The Qt resource system has been there way before Qt 4.7.

              You may have to write the file by hand but it's not that hard. See here.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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