我正在创建桌面环境,我需要在屏幕顶部为任务栏预留空间。目前无法关闭(例如)Chromium - 关闭/最大化/最小化按钮位于任务栏后面。如何在屏幕上预留空间?
以下是代码:
#include "status_bar.h"
#include "ui_status_bar.h"
#include <stdlib.h>
#include <QTime>
#include <QTimer>
#include <QApplication>
#include <QDesktopWidget>
#include "menu.h"
#include "ui_menu.h"
status_bar::status_bar(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::status_bar)
{
ui->setupUi(this);
setWindowFlags(Qt::Window | Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
move(0,0);
menudialog = new QDialog(0,0);
setMinimumSize(QApplication::desktop()->width(),36);
setMaximumSize(QApplication::desktop()->width(),36);
ui->menu_switch->move(size().width()/2-ui->menu_switch->size().width(),0);
ui->time->move(QApplication::desktop()->width()-ui->time->size().width(),10);
ui->username->setText(getenv("USER"));
timeupdate = new QTimer(this);
is_menu_open=false;
connect(timeupdate, SIGNAL(timeout()),
this, SLOT(UpdateClock()));
timeupdate->start(100);
}
void status_bar::UpdateClock()
{
ui->time->setText(QTime::currentTime().toString("HH:mm"));
}
status_bar::~status_bar()
{
delete ui;
}
void status_bar::on_menu_switch_clicked()
{
if(is_menu_open) {
menudialog->close();
is_menu_open=false;
} else {
is_menu_open=true;
Ui_menu menuui;
menuui.setupUi(menudialog);
menudialog->setMinimumSize(QApplication::desktop()->width(),QApplication::desktop()->height()-36);
menudialog->setMaximumSize(QApplication::desktop()->width(),QApplication::desktop()->height()-36);
menudialog->move(0,36);
menudialog->setWindowFlags(Qt::Window | Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
menudialog->show();
}
}