Results 1 to 19 of 19

Thread: How to make a borderless window staying on the top of the system?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to make a borderless window staying on the top of the system?

    Qt Code:
    1. setWindowFlags(Qt::WindowStaysOnTopHint);
    2. setWindowFlags(Qt::FramelessWindowHint);
    To copy to clipboard, switch view to plain text mode 
    Use this, the window is borderless, but it does not stay on top.

    Qt Code:
    1. setWindowFlags(Qt::FramelessWindowHint);
    2. setWindowFlags(Qt::WindowStaysOnTopHint);
    To copy to clipboard, switch view to plain text mode 
    The window stays on top, but it has a border.

    Please help, thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make a borderless window staying on the top of the system?

    It won't work A frameless window is ignored by the window manager. On the other hand the window manager is responsible for honouring (or not) the stays-on-top hint. You can try masking the border out using QWidget::setMask().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Cupidvogel (3rd January 2016)

  4. #3
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a borderless window staying on the top of the system?

    You are almighty.
    Thanks a lot!

  5. #4
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a borderless window staying on the top of the system?

    An extended question:
    By using QWidget::setMask(), the frameless window stays on top now.
    But how can i make this window translucent?

    Thanks.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make a borderless window staying on the top of the system?

    Try setting the Qt::WA_TranslucentBackground attribute.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a borderless window staying on the top of the system?

    Thanks for advice!
    Qt Code:
    1. setStyleSheet("background-color: transparent;");
    2. setAttribute(Qt::WA_TranslucentBackground);
    3. setMask(geometry());
    4. setWindowFlags(Qt::X11BypassWindowManagerHint);
    5. setWindowFlags(Qt::FramelessWindowHint);
    6. setWindowFlags(Qt::WindowStaysOnTopHint);
    To copy to clipboard, switch view to plain text mode 
    The window's background is black because Qt::FramelessWindowHint will be ignored.

    Qt Code:
    1. setStyleSheet("background-color: transparent;");
    2. setAttribute(Qt::WA_TranslucentBackground);
    3. setMask(geometry());
    4. setWindowFlags(Qt::X11BypassWindowManagerHint);
    5. setWindowFlags(Qt::WindowStaysOnTopHint);
    6. setWindowFlags(Qt::FramelessWindowHint);
    To copy to clipboard, switch view to plain text mode 
    This way, the window is transparent but it will not stay on top.

    I have seen a program that its frameless window is translucent and it can stay on top. That's really cool.
    Last edited by moiit; 12th October 2011 at 17:23.

  8. The following user says thank you to moiit for this useful post:

    sourena (13th August 2012)

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make a borderless window staying on the top of the system?

    Why do you want to bypass the window manager and make the window frameless? Isn't setMask enought?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #8
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a borderless window staying on the top of the system?

    Quote Originally Posted by wysota View Post
    Why do you want to bypass the window manager and make the window frameless? Isn't setMask enought?
    Ok, i delete this row, but problem still there:
    First:
    setStyleSheet("background-color: transparent;");
    setAttribute(Qt::WA_TranslucentBackground);
    setMask(geometry());

    Next:
    To make transparent, it seems Qt::FramelessWindowHint need to be set.
    To make stay-on-top, Qt::WindowStaysOnTopHint need to be set.
    ie., frameless && stay-on-top && translucent == false.
    So i guess there must be another method that may solve this issue.

    Just tested, for Win7, getting Aero effect is no need Qt::FramelessWindowHint, with stay-on-top working, but it has a Win7 titleBar.
    If using setMask(geometry()), the titleBar is removed, with stay-on-top working, but no longer Aero, instead, it becomes translucent.

    This means, for Win7, frameless && stay-on-top && translucent == true.

    Then for other systems, how to?
    Last edited by moiit; 13th October 2011 at 06:52.

  11. #9
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a borderless window staying on the top of the system?

    Ok, now the question is:
    How to make transparent without Qt::FramelessWindowHint to be set? (setWindowOpacity() is not a good idea)
    Last edited by moiit; 13th October 2011 at 08:07.

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make a borderless window staying on the top of the system?

    To make something transparent, set the WA_TranslucentBackground attribute and make sure the widget doesn't paint any background. Don't use stylesheets, they are not needed here. Use only setMask and translucent background. How to remove the background depends on the widget you are using --- surely autoFillBackgorund needs to be set to false and possibly you need to alter QPalette to include transparent brush for the background.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #11
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a borderless window staying on the top of the system?

    Thanks for your answer.
    Qt Code:
    1. setMask(geometry());
    2. setWindowFlags(Qt::WindowStaysOnTopHint);
    3. setAttribute(Qt::WA_TranslucentBackground,true);
    4. setAutoFillBackground(false);
    5. QPalette pal = palette();
    6. pal.setColor(QPalette::Background, QColor (0, 0 , 0, 20));
    7. setPalette(pal);
    To copy to clipboard, switch view to plain text mode 
    This won't work. The background is still black.
    Last edited by moiit; 13th October 2011 at 09:54.

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make a borderless window staying on the top of the system?

    This works just fine for me:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Widget : public QWidget {
    4. public:
    5. Widget() : QWidget() {
    6. setAttribute(Qt::WA_TranslucentBackground);
    7. setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
    8. }
    9. protected:
    10. void paintEvent(QPaintEvent *pe) {
    11. QPainter p(this);
    12. p.setBrush(Qt::red);
    13. p.setRenderHint(QPainter::Antialiasing);
    14. p.drawEllipse(rect().adjusted(50,50,-50,-50));
    15. }
    16. void resizeEvent(QResizeEvent *re) {
    17. setMask(rect());
    18. }
    19. };
    20.  
    21. int main(int argc, char **argv) {
    22. QApplication app(argc, argv);
    23. Widget w;
    24. w.show();
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #13
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to make a borderless window staying on the top of the system?

    Quote Originally Posted by wysota View Post
    It won't work A frameless window is ignored by the window manager. On the other hand the window manager is responsible for honouring (or not) the stays-on-top hint. You can try masking the border out using QWidget::setMask().
    I've got this code:

    WidgetTest.pro
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = WidgetTest
    4.  
    5. TEMPLATE = app
    6.  
    7. SOURCES += main.cpp \
    8. mywidget.cpp
    9.  
    10. HEADERS += \
    11. mywidget.h
    To copy to clipboard, switch view to plain text mode 

    mywidget.h
    Qt Code:
    1. #ifndef MYWIDGET_H
    2. #define MYWIDGET_H
    3.  
    4. #include <QWidget>
    5.  
    6. class MyWidget : public QWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit MyWidget(QWidget *parent = 0);
    11. ~MyWidget();
    12. };
    13.  
    14. #endif // MYWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    mywidget.cpp
    Qt Code:
    1. #include "mywidget.h"
    2.  
    3. MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
    4. {
    5. setWindowFlags( Qt::FramelessWindowHint );
    6. }
    7.  
    8. MyWidget::~MyWidget()
    9. {
    10. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mywidget.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. MyWidget myWidget;
    9. myWidget.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    And it pops up with a grey window with no border. How does that work?

  16. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make a borderless window staying on the top of the system?

    Quote Originally Posted by Atomic_Sheep View Post
    And it pops up with a grey window with no border. How does that work?
    Qt::FramelessWindowHint is a request to not have a border.

    You set this flag, the windowing system apparently allows it, you get a frameless (no border) window.

    Cheers,
    _

Similar Threads

  1. Setting the system time make the Qt program blocked.
    By alps_xing in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2010, 08:12
  2. Replies: 2
    Last Post: 10th December 2009, 07:01
  3. how to make system calls to be displayed in QLineEdit
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 05:08
  4. Replies: 2
    Last Post: 12th October 2008, 01:55
  5. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43

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
  •  
Qt is a trademark of The Qt Company.