Results 1 to 7 of 7

Thread: Image without window frame?

  1. #1
    Join Date
    Feb 2008
    Posts
    1

    Default Image without window frame?

    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!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image without window frame?

    Yes, render the image on a QWidget or set it on a QLabel and use:
    Qt Code:
    1. 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.

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Image without window frame?

    Qt Code:
    1. #include <QtGui>
    2. int main (int argc, char **argv)
    3. {
    4.  
    5. QApplication app(argc,argv);
    6. QLabel *lab=new QLabel(0,Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    7. QPixmap *p=new QPixmap("plane.jpg");
    8. QPixmap p1(p->scaled ( lab->width(),lab->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ));
    9. lab->setPixmap(p1);
    10. lab->show();
    11. lab->adjustSize();
    12. return app.exec();
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    I hope it helps also.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Image without window frame?

    Quote Originally Posted by ashukla View Post
    Qt Code:
    1. #include <QtGui>
    2. int main (int argc, char **argv)
    3. {
    4.  
    5. QApplication app(argc,argv);
    6. QLabel *lab=new QLabel(0,Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    7. QPixmap *p=new QPixmap("plane.jpg");
    8. QPixmap p1(p->scaled ( lab->width(),lab->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ));
    9. lab->setPixmap(p1);
    10. lab->show();
    11. lab->adjustSize();
    12. return app.exec();
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    I hope it helps also.
    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

  5. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Image without window frame?

    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!

  6. #6
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Image without window frame?

    Qt Code:
    1. #include <QApplication>
    2. #include <QPixmap>
    3. #include <QLabel>
    4. int main (int argc, char **argv)
    5. {
    6.  
    7. QApplication app(argc,argv);
    8. QLabel lab(0,Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    9. QPixmap p("plane.jpg");
    10.  
    11.  
    12. lab.setText("Hello");
    13. lab.show();
    14. lab.resize(300,200);
    15. p=p.scaled ( lab.width(),lab.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
    16. lab.setPixmap(p);
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    Dear JPN!
    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!

  7. #7
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image without window frame?

    Quote Originally Posted by ashukla View Post
    Qt Code:
    1. #include <QApplication>
    2. #include <QPixmap>
    3. #include <QLabel>
    4. int main (int argc, char **argv)
    5. {
    6.  
    7. QApplication app(argc,argv);
    8. QLabel lab(0,Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    9. QPixmap p("plane.jpg");
    10.  
    11.  
    12. lab.setText("Hello");
    13. lab.show();
    14. lab.resize(300,200);
    15. p=p.scaled ( lab.width(),lab.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
    16. lab.setPixmap(p);
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    Dear JPN!
    Now, You should happy for above. Give any suggestion with free mind.
    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:
    1. #include <QLabel>
    2. #include <QApplication>
    3. int main (int argc, char **argv) {
    4. QApplication app(argc,argv);
    5. QLabel lab(0,Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    6. lab.resize(300,200);
    7. lab.setPixmap(QPixmap("plane.png"));
    8. lab.setScaledContents(true);
    9. lab.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Any more improvements possible?

Similar Threads

  1. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 09:30
  2. Main Window frame height
    By ^NyAw^ in forum Qt Programming
    Replies: 18
    Last Post: 13th November 2007, 12:14
  3. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  4. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 15:40
  5. Replies: 15
    Last Post: 23rd March 2007, 16:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.