Hello!
Is it possible to just view an image without frame (minimize, maximize, close buttons) somewhere on the screen (should be always in the foreground) ?
Thank you very much!
Hello!
Is it possible to just view an image without frame (minimize, maximize, close buttons) somewhere on the screen (should be always in the foreground) ?
Thank you very much!
Yes, render the image on a QWidget or set it on a QLabel and use:
Qt Code:
imageContainer->setWindowFlags(imageContainer->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);To copy to clipboard, switch view to plain text mode
However, you won't be able to interact with the widget. You will have to add a dditional functionality to be able to move it with the mouse, etc.
I hope it helps also.Qt Code:
#include <QtGui> int main (int argc, char **argv) { QPixmap p1(p->scaled ( lab->width(),lab->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation )); lab->setPixmap(p1); lab->show(); lab->adjustSize(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
Sorry, I can't resist commenting on this because there are roughly as many programming errors as there are lines:
- "QLabel* lab" is never deleted. Why not just allocate it on the stack anyway so it goes out of scope properly after app.exec() returns?
- Why two different instances of QPixmap?
- Why allocate one of pixmaps on the heap? First of all it's never deleted and secondly QPixmap is an implicitly shared class.
- Querying widget size ("lab->width(),lab->height()") returns bogus values until the widget has been shown or resized for the first time.
- QLabel is able to scale its contents on its own, see QLabel::scaledContents.
- When a widget is shown, it's initial size is calculated based on its sizeHint(), thus calling adjustSize() is futile.
It doesn't really matter if one deletes anything in a small sample application like this. The OS will free allocated resources anyway once the application quits. But I'm just worried how one manages to write robust real life applications without constant memory leaks if he gets to the habit of programming like this. It's a common misbelief that Qt deletes everything you don't. There is no magic garbage collection. Every QObject deletes its children but nothing more. QPixmap is not a QObject and QLabel has no parent in the code above so neither of them gets deleted.
J-P Nurmi
Dear JPN!
You are right and I am accustomed to do object allocation & deallocation in real projects.
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
Dear JPN!Qt Code:
#include <QApplication> #include <QPixmap> #include <QLabel> int main (int argc, char **argv) { lab.setText("Hello"); lab.show(); lab.resize(300,200); p=p.scaled ( lab.width(),lab.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); lab.setPixmap(p); return app.exec(); }To copy to clipboard, switch view to plain text mode
Now, You should happy for above. Give any suggestion with free mind.
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
Oooh, can I nitpick too?
You need an #include <QApplication> for this to compile
You don't need to #include <QPixmap> as that gets pulled in by QLabel
Setting "hello" as the labels text does nothing since it will just show the image
Calling show() on the label doesn't actually show the label until control returns to the event loop, so theoretically width() and height() won't work properly (although it seems that they do anyway here)
You don't need to scale the image yourself.
Here's how I would do it.
Qt Code:
#include <QLabel> #include <QApplication> int main (int argc, char **argv) { lab.resize(300,200); lab.setScaledContents(true); lab.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Any more improvements possible?
Bookmarks