fpujol
9th November 2007, 10:28
Hello,
I'm using QTableView to consult records and a QDialog for modify the records. In QTableView I use QItemDelegate for see images, that are saved in bytea format in postgresql database. I have obtained put the image in database in byte format:
if (ui.qLnFitxerSel->text().length()>0)
{
QPixmap pixmap(ui.qLnFitxerSel->text(), "PNG" );
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");
qSqlTableModel->setData(q->getAKSqlTableModel()->index(row,
akFrontData->getAKSqlTableModel()->fieldIndex("bandera")), bytes);
}
In my Qdialog I want to see the Image trought QLabel and I use the QDataWidgetMapper but this returns me the Image in byte information
so I see the QLabel something like this: PNG..![]... how I could do that
when QDataWidgetMapper return's me the information of qlabel it converts
it as Image and not in text, setting qLabel as QPixmap.
void AKEntitat::mapFields(QSqlQueryModel * model)
{
QSqlRecord qSqlRecord = model->record();
int count = qSqlRecord.count();
for (int i=0; i<=count; i++)
{
QSqlField qSqlCamp = qSqlRecord.field(i);
akCampBd = searchAKCampBd(qSqlCamp.name());
qLabel = searchLabel(qSqlCamp.name());
if (akCampBd!=0)
{
qDataWidgetMapper->addMapping(akCampBd->akCamp, i);
}
if (qLabel!=0)
{
qDataWidgetMapper->addMapping(qLabel, i);
}
}
qDataWidgetMapper->toFirst();
connect(akTaula->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) ,
qDataWidgetMapper, SLOT(setCurrentModelIndex(QModelIndex)));
}
Thank you
I'm using QTableView to consult records and a QDialog for modify the records. In QTableView I use QItemDelegate for see images, that are saved in bytea format in postgresql database. I have obtained put the image in database in byte format:
if (ui.qLnFitxerSel->text().length()>0)
{
QPixmap pixmap(ui.qLnFitxerSel->text(), "PNG" );
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");
qSqlTableModel->setData(q->getAKSqlTableModel()->index(row,
akFrontData->getAKSqlTableModel()->fieldIndex("bandera")), bytes);
}
In my Qdialog I want to see the Image trought QLabel and I use the QDataWidgetMapper but this returns me the Image in byte information
so I see the QLabel something like this: PNG..![]... how I could do that
when QDataWidgetMapper return's me the information of qlabel it converts
it as Image and not in text, setting qLabel as QPixmap.
void AKEntitat::mapFields(QSqlQueryModel * model)
{
QSqlRecord qSqlRecord = model->record();
int count = qSqlRecord.count();
for (int i=0; i<=count; i++)
{
QSqlField qSqlCamp = qSqlRecord.field(i);
akCampBd = searchAKCampBd(qSqlCamp.name());
qLabel = searchLabel(qSqlCamp.name());
if (akCampBd!=0)
{
qDataWidgetMapper->addMapping(akCampBd->akCamp, i);
}
if (qLabel!=0)
{
qDataWidgetMapper->addMapping(qLabel, i);
}
}
qDataWidgetMapper->toFirst();
connect(akTaula->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) ,
qDataWidgetMapper, SLOT(setCurrentModelIndex(QModelIndex)));
}
Thank you