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