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. [solved]Pushbutton and Icons
QtWS25 Last Chance

[solved]Pushbutton and Icons

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 2.8k 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.
  • T Offline
    T Offline
    toho71
    wrote on last edited by
    #1

    I got problems when I'm going to change an icon on a button.
    the button gets blank with no Icon:
    My code

    @fileName.append("\Icons\NBStartup.png");
    ui->btnNB->setIcon(QIcon(fileName));
    @
    My platform is Linux Debian.
    [Edit: Please use @-tags for code snippets /Vass]

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      So... after fileName.append, what does filename contain exactly? Is that really the path to your icon file?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leon.anavi
        wrote on last edited by
        #3

        In my opinion there is a problem with the file or the path to it. You can add a check to verify that the file of the icon exists:

        @
        QFile myIcon( fileName );
        if( true == myIcon.exists() )
        {
        ui->btnNB->setIcon(QIcon(fileName));
        }
        else
        {
        qDebug() << "File does not exists!";
        }
        @

        http://anavi.org/

        1 Reply Last reply
        0
        • T Offline
          T Offline
          toho71
          wrote on last edited by
          #4

          It's solved
          filename.append("/Icons/NBStartup.png")
          No backslash ;

          It's working

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            From the documentation about QFile:
            QFile expects the file separator to be '/' regardless of operating system. The use of other separators (e.g., '') is not supported.

            I believe it is a bad idea to hard code '/' anyway, you should use Qdir::separator instead.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              [quote author="fluca1978" date="1316606616"]
              I believe it is a bad idea to hard code '/' anyway, you should use Qdir::separator instead.[/quote]

              No, hard coding '/' is indeed the proper way. From the QDir::separator() documentation:

              bq. You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators().

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              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