PDA

View Full Version : problem with .bmp



IRON_MAN
2nd July 2009, 07:49
Hello,

I have a problem! My images are .bmp. I have loaded them to my new proyect giving a new name as you did "00b.qrc"... and then, in the place that you set in note of test.cpp:



const QString bin = QString::number(r) + QString::number(c) + "b.png";
const QString fin = QString::number(r) + QString::number(c) + "f.png";

I change for :


const QString bin = QString::number(r) + QString::number(c) + "b.bmp";
const QString fin = QString::number(r) + QString::number(c) + "f.bmp";

What I'm doing wrong?

Lykurg
2nd July 2009, 08:14
I have loaded them to my new proyect giving a new name as you did "00b.qrc"...
As who did? And have you a image plugin that support bmp files?

IRON_MAN
2nd July 2009, 08:48
The code is the following one. With another aplications I can work with images .bmp


#include <QtGui>
#include "test.h"

Test::Test(QWidget *parent)
: QDialog(parent), m_rows(5), m_columns(2)
{
m_gl = new QGridLayout(this);
init();
}

void Test::init()
{
for (int r = 0; r < m_rows; ++r) {
for (int c = 0; c < m_columns; ++c) {
QPushButton *pb = new QPushButton();
pb->setProperty("state", Background);
const QString bin = QString::number(r) + QString::number(c) + "b.png";
const QString fin = QString::number(r) + QString::number(c) + "f.png";

QPixmap fp(10, 10);
fp.fill(QColor(qrand()%255, qrand()%255, qrand()%255));
fp.save(fin);//must be optimized

QPixmap bp(10, 10);
bp.fill(QColor(qrand()%255, qrand()%255, qrand()%255));
bp.save(bin);//must be optimized

pb->setProperty("backgroundImageName", bin);
pb->setProperty("foregroundImageName", fin);
//pb->setText("Background");
pb->setIcon(QIcon(bp));
connect(pb, SIGNAL(clicked()), SLOT(changeImage()));
m_gl->addWidget(pb, r, c);
}
}
}

void Test::changeImage()
{
QPushButton *pb = qobject_cast<QPushButton *>(sender());
if (!pb)
return;
const State state = State(pb->property("state").toInt());
// pb->setText(state == Background ? "Foreground" : "Background");
pb->setProperty("state", state == Background ? Foreground : Background);
const QString fileName = (state == Background ? pb->property("foregroundImageName").toString() : pb->property("backgroundImageName").toString());
pb->setIcon(QIcon(fileName));
}