1

I have written a code to print an Icon accessed from FontAwesome installed in the system. I would like to change the color for the Icon printed on the Screen.I have tried using QPixmap and QIcon,but to no avail.Attached the output :enter image description here

#include "MainWindow.h"
#include "ui_MainWindow.h"

#include <QPushButton>
#include <QGridLayout>
#include <QWidget>
#include <QLabel>

#include "qfonticon.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QWidget *centralWidget;
    QGridLayout *gridLayout;

    centralWidget = new QWidget(this);
    gridLayout = new QGridLayout( centralWidget );

    QFontIcon::addFont("/usr/share/fonts/fontawesome-webfont.ttf");



        QIcon icon = QFontIcon::icon(0xf2e0,QColor(1,0,1,255));

        //QFontIconEngine::addFile("/usr/share/fonts/fontawesome-webfont.ttf");
        //QPixmap pix = QFontIconEngine::;
        QPushButton *b = new QPushButton();
        //QLabel *l = new QLabel();
        b->setIcon(icon);
        b->setIconSize(QSize(75,75));
        //l->setPixmap(pix);
        gridLayout->addWidget(b);
        //gridLayout->addWidget(l);

    this->setCentralWidget(centralWidget);
}

MainWindow::~MainWindow()
{
    delete ui;
}
  • @G.M Hi G.M., I was hoping if you could help me out with the above situation. – theindianphil1 Jan 16 '17 at 10:53
  • @eyllanesc I was hoping if you could help me out with the above situation – theindianphil1 Jan 16 '17 at 10:54
  • The `QColor(1,0,1,255)` you're using in the posted code is, essentially, black which is what you're seeing. What happens if you just use something like `Qt::red`? Does that still just show a black icon? The `baseColor` parameter to `QFontIcon::icon` certainly works as expected when I try it. – G.M. Jan 16 '17 at 12:47

0 Answers0