For designing a custom made pushButton I added a picture source (1):
#include "mybutton.h"
#include <QDebug>
#include <QDir>
#include <QIcon>
#include <QPixmap>
MyButton::MyButton(QWidget *parent) : QPushButton(parent) {
QPixmap pixmap("/home/myCode/MyButton/MyButton/graphics/myPicture.png"); //(1) picture source
QIcon buttonIcon;
buttonIcon.addPixmap(pixmap);
this->setIcon(buttonIcon);
this->setIconSize(pixmap.rect().size());
}
Of course, sometimes the local path to picture changes.
So instead I would like to tell Qt at compile time something like this: Path to file is workspacefolder/graphics/myPicture.png
Like in VS Code you can configure build tasks (tasks.json) for compiling with g++ and refer with variable ${workspaceFolder}.
I tried using functions of QDir-Class, but that one only return when debugging, not at compile time.
qDebug() << QDir::currentPath();
Is it possible to return the workspaceFolder with help of QDir-functions?