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. I cannot set QPixmap without passing the whole directory

I cannot set QPixmap without passing the whole directory

Scheduled Pinned Locked Moved Unsolved General and Desktop
pathfile pathdirectorydirectory strucqpixmap
2 Posts 2 Posters 542 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.
  • F Offline
    F Offline
    FarukErat
    wrote on 9 Mar 2022, 10:05 last edited by FarukErat 3 Sept 2022, 10:08
    #1

    I have been trying to get the images to show. However, I haven't been able to do it. I wanna shorten tha path to ":/res/black.bmp". Since, otherwise, it won't work on others computers.

    const char BLACK_PATH[] = "C:/Users/Username/Documents/othello/res/black.bmp";
    const char WHITE_PATH[] = "C:/Users/Username/Documents/othello/res/white.bmp";
    const char EMPTY_PATH[] = "C:/Users/Username/Documents/othello/res/empty.bmp";
    const char LEGAL_BLACK_PATH[] = "C:/Users/Username/Documents/othello/res/legal_black.bmp";
    const char LEGAL_WHITE_PATH[] = "C:/Users/Username/Documents/othello/res/legal_white.bmp";

    void MainWindow::updateBtns()
    {
    QPixmap black(BLACK_PATH);
    QPixmap white(WHITE_PATH);
    QPixmap empty(EMPTY_PATH);
    QPixmap legal_black(LEGAL_BLACK_PATH);
    QPixmap legal_white(LEGAL_WHITE_PATH);
    for (int row = 0; row < SIZE; row++)
    {
    for (int col = 0; col < SIZE; col++)
    {
    switch (this->board[row][col])
    {
    case BLACK:
    {
    labels[row][col]->setPixmap(black);
    }
    break;
    case WHITE:
    {
    labels[row][col]->setPixmap(white);
    }
    break;
    case EMPTY:
    {
    labels[row][col]->setPixmap(empty);
    }
    break;
    case LEGAL:
    if (marking)
    {
    if (this->turn == BLACK)
    labels[row][col]->setPixmap(legal_black);
    else
    labels[row][col]->setPixmap(legal_white);
    }
    break;
    }
    }
    }
    }

    J 1 Reply Last reply 9 Mar 2022, 10:14
    0
    • F FarukErat
      9 Mar 2022, 10:05

      I have been trying to get the images to show. However, I haven't been able to do it. I wanna shorten tha path to ":/res/black.bmp". Since, otherwise, it won't work on others computers.

      const char BLACK_PATH[] = "C:/Users/Username/Documents/othello/res/black.bmp";
      const char WHITE_PATH[] = "C:/Users/Username/Documents/othello/res/white.bmp";
      const char EMPTY_PATH[] = "C:/Users/Username/Documents/othello/res/empty.bmp";
      const char LEGAL_BLACK_PATH[] = "C:/Users/Username/Documents/othello/res/legal_black.bmp";
      const char LEGAL_WHITE_PATH[] = "C:/Users/Username/Documents/othello/res/legal_white.bmp";

      void MainWindow::updateBtns()
      {
      QPixmap black(BLACK_PATH);
      QPixmap white(WHITE_PATH);
      QPixmap empty(EMPTY_PATH);
      QPixmap legal_black(LEGAL_BLACK_PATH);
      QPixmap legal_white(LEGAL_WHITE_PATH);
      for (int row = 0; row < SIZE; row++)
      {
      for (int col = 0; col < SIZE; col++)
      {
      switch (this->board[row][col])
      {
      case BLACK:
      {
      labels[row][col]->setPixmap(black);
      }
      break;
      case WHITE:
      {
      labels[row][col]->setPixmap(white);
      }
      break;
      case EMPTY:
      {
      labels[row][col]->setPixmap(empty);
      }
      break;
      case LEGAL:
      if (marking)
      {
      if (this->turn == BLACK)
      labels[row][col]->setPixmap(legal_black);
      else
      labels[row][col]->setPixmap(legal_white);
      }
      break;
      }
      }
      }
      }

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 9 Mar 2022, 10:14 last edited by
      #2

      @FarukErat said in I cannot set QPixmap without passing the whole directory:

      I wanna shorten tha path to ":/res/black.bmp".

      Then you need to put them into a resource file: https://doc.qt.io/qt-5/resources.html

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

      1 Reply Last reply
      5

      2/2

      9 Mar 2022, 10:14

      • Login

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