franco.amato
30th March 2017, 20:35
Good morning,
I would have a help in showing a background image to a QGraphicsView.
I have an app develop to edit images and before displaying the images that have to be edited I would display a logo.
Reading docs I think to use the QGraphicsView::drawBackground so in brief this is what I did
// Ctor of my class derived from QGraphicsView
PageView::PageView(QWidget *parent) : QGraphicsView(parent)
{
// ...
// more code
if ( m_logoPixmap.load(":/Resources/Logos/editor_logo_v.png"))
{
// scale it
m_logoScaledPixmap = m_logoPixmap.scaled(QSize(viewport()->width() / 3, viewport()->height() / 3), Qt::KeepAspectRatio, Qt::SmoothTransformation); // Incorrect size
}
}
I would scale it to be a percentage of the view but i can not get the correct size ( I always get 100, 30 )
// Here I would show the logo
void PageView::drawBackground(QPainter *painter, const QRectF &rect)
{
QRectF pixmapBoundingRect = m_logoScaledPixmap.rect();
qreal maxValue = qMax(pixmapBoundingRect.width(), pixmapBoundingRect.height());
painter->drawPixmap(pixmapBoundingRect, m_logoScaledPixmap, QRect(0.0, 0.0, m_logoScaledPixmap.width(), m_logoScaledPixmap.height())); // Not centered
}
I would the logo to be centered and is also pixeled when scaled even adding Qt::SmoothTransformation ( its original size is 2000 * 2000 pixels ).
I also would the logo to disappear when I load images to be edited
Thanx
I would have a help in showing a background image to a QGraphicsView.
I have an app develop to edit images and before displaying the images that have to be edited I would display a logo.
Reading docs I think to use the QGraphicsView::drawBackground so in brief this is what I did
// Ctor of my class derived from QGraphicsView
PageView::PageView(QWidget *parent) : QGraphicsView(parent)
{
// ...
// more code
if ( m_logoPixmap.load(":/Resources/Logos/editor_logo_v.png"))
{
// scale it
m_logoScaledPixmap = m_logoPixmap.scaled(QSize(viewport()->width() / 3, viewport()->height() / 3), Qt::KeepAspectRatio, Qt::SmoothTransformation); // Incorrect size
}
}
I would scale it to be a percentage of the view but i can not get the correct size ( I always get 100, 30 )
// Here I would show the logo
void PageView::drawBackground(QPainter *painter, const QRectF &rect)
{
QRectF pixmapBoundingRect = m_logoScaledPixmap.rect();
qreal maxValue = qMax(pixmapBoundingRect.width(), pixmapBoundingRect.height());
painter->drawPixmap(pixmapBoundingRect, m_logoScaledPixmap, QRect(0.0, 0.0, m_logoScaledPixmap.width(), m_logoScaledPixmap.height())); // Not centered
}
I would the logo to be centered and is also pixeled when scaled even adding Qt::SmoothTransformation ( its original size is 2000 * 2000 pixels ).
I also would the logo to disappear when I load images to be edited
Thanx