
Originally Posted by
mickey
I don't understand how you say me use QLabel for my aim; beyond this, I used pixmap; and I think using qlabel (?) my problem will persists: my image appears distorted (texture 32x32). Am I wrong? (I'd like show it more large, for this I thinked to repeat an QImage on a QPixmap) Thanks
Ah, the aspect ratio of your image is being distorted. In this case, you should create a QImage and scale it up to the correct size, while retaining the aspect ratio: Something like:
void previewUrl(const QUrl& rUrl)
{
if (im.isNull())
{
setText( "This is not a pixmap" );
}
else
{
im
= im.
smoothScale(width
(), height
(),
QImage::ScaleMin);
}
}
void previewUrl(const QUrl& rUrl)
{
QString path = rUrl.path();
QImage im(path);
if (im.isNull())
{
setText( "This is not a pixmap" );
}
else
{
im = im.smoothScale(width(), height(), QImage::ScaleMin);
setPixmap(QPixmap(im));
}
}
To copy to clipboard, switch view to plain text mode
If you just want to tile the image, use this instead:
void previewUrl(const QUrl& rUrl)
{
if (p.isNull())
{
setText( "This is not a pixmap" );
}
else
{
setPaletteBackgroundPixmap(p);
}
}
void previewUrl(const QUrl& rUrl)
{
QString path = rUrl.path();
QPixmap p(path);
if (p.isNull())
{
setText( "This is not a pixmap" );
}
else
{
setPaletteBackgroundPixmap(p);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks