Qt/win: showMaximized() overlapping taskbar on a frameless window

与世无争的帅哥 提交于 2019-12-10 13:25:26

问题


I'm building an application that has its own custom chrome. I have turned the default window border off by setting the flag:

this->setWindowFlags(Qt::FramelessWindowHint);

After this flag is set and the default window border is turned off, any calls to:

this->showMaximized();

result in a window that takes up the entire screen, overlapping the task bar. Is there a common work around for this or another method I should be calling instead of showMaximized()?

Win7/Qt4.6


回答1:


If you inherit from QDesktopWidget, you'd be able to use availableGeometry(), which returns the available geometry of the screen with index screen based on what the platform decides is available (for example excludes the dock and menu bar on Mac OS X, or the task bar on Windows).

#ifndef WIDGET_H
#define WIDGET_H

#include <QtGui>
class Widget : public QDesktopWidget
{
    Q_OBJECT
public:
    Widget(QWidget *parent = 0);
    ~Widget();
};

#endif // WIDGET_H



#include "widget.h"
#include <QtGui>

Widget::Widget(QWidget *parent) : QDesktopWidget()
{
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->showMaximized();
    this->resize(width(), availableGeometry().height());
}

Widget::~Widget()
{

}



回答2:


You should not inherit from QDesktopWidget.

You can get the "available geometry" by getting the QDesktopWidget instance from QApplication::desktop:

QDesktopWidget *desktop = QApplication::desktop();
// Because reserved space can be on all sides of the scren
// you have to both move and resize the window
this->setGeometry(desktop->availableGeometry());


来源:https://stackoverflow.com/questions/2641193/qt-win-showmaximized-overlapping-taskbar-on-a-frameless-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!