C++ 如何删除标题栏左侧的默认菜单-Qt?

C++ 如何删除标题栏左侧的默认菜单-Qt?,c++,qt,C++,Qt,这将删除最小化、最大化和关闭按钮。左侧的默认菜单仍然存在。如何摆脱它 我希望标题栏在那里,但只希望菜单被删除 默认菜单包含:最小化、最大化、移动等选项 编辑1: timer.cpp Qt :: WindowFlags flags = 0; // Makes the Pomodoro stay on the top of all windows. flags |= Qt :: WindowStaysOnTopHint; // Removes minimize,

这将删除最小化、最大化和关闭按钮。左侧的默认菜单仍然存在。如何摆脱它

我希望标题栏在那里,但只希望菜单被删除

默认菜单包含:最小化、最大化、移动等选项

编辑1: timer.cpp

    Qt :: WindowFlags flags = 0;

    // Makes the Pomodoro stay on the top of all windows.
    flags |= Qt :: WindowStaysOnTopHint;

    // Removes minimize, maximize, and close buttons.
    flags |= Qt :: WindowTitleHint | Qt :: CustomizeWindowHint;

    window->setWindowFlags (flags);
    window->setWindowTitle ("Failing to plan is planning to fail");
#包括
#包括
#包括“timer.h”
#包括
#包括
#包括
#包括
int main(int argc,char*argv[])
{
QApplication应用程序(argc、argv);
//我们将放置计时器的窗口。
QMainWindow*window=新的QMainWindow();
QWidget*centralWidget=新的QWidget(窗口);
/*按钮小部件*/
//在主窗口上显示一个按钮。
QPushButton*startButton=新的QPushButton(“开始”,窗口);
//设置按钮小部件的大小。
开始按钮->设置固定大小(245,25);
/*文本框*/
//在主窗口上显示时间间隔列表。
QListWidget*timeIntervalList=新的QListWidget(窗口);
timeIntervalList->setFixedSize(30145);
QStringList时间间隔;
时间间隔setWindowTitle(“计划失败即计划失败”);
QGridLayout*布局=新的QGridLayout();
centralWidget->setLayout(布局);
//在此处向QGridLayout添加项目
//行和列计数是自动设置的
布局->添加小部件(objLcdDisplay,0,1);
布局->添加小部件(开始按钮,1,1);
布局->添加小部件(timeIntervalList,0,0);
窗口->设置中心Widget(中心Widget);
窗口->显示();
返回app.exec();
}
定时器

#include <QApplication>
#include <QMainWindow>
#include "timer.h"

#include <QPushButton>
#include <QListWidget>
#include <QtGui>
#include <QTreeWidget>
int main(int argc, char *argv[])
{
    QApplication    app (argc, argv);

    // The window on which we will place the timer.
    QMainWindow *window           = new QMainWindow();
    QWidget           *centralWidget = new QWidget (window);

    /* Button widget */
    // Displays a button on the main window.
    QPushButton   *startButton     = new QPushButton("Start", window);
    // Setting the size of the button widget.
    startButton->setFixedSize (245, 25);

    /* Text box */
    // Displays a time interval list on the main window.
    QListWidget *timeIntervalList = new QListWidget (window);
    timeIntervalList->setFixedSize (30, 145);

    QStringList timeIntervals;
    timeIntervals << "1" << "20" << "30" << "40";
    timeIntervalList->addItems (timeIntervals);

    /* LCD widget */
    // Start Counting down from 25 minutes
    lcdDisplay *objLcdDisplay = new lcdDisplay (centralWidget);
    // Setting the size of the LCD widget.
    objLcdDisplay->setFixedSize (245, 140);

    // The clicked time interval should be returned from the list to the timer.
    QObject :: connect (timeIntervalList, SIGNAL (itemClicked (QListWidgetItem *)), objLcdDisplay, SLOT (receiveTimeInterval (QListWidgetItem *)));

    // The timer should start and emit signals when the start button is clicked.
    QObject :: connect (startButton, SIGNAL (clicked ()), objLcdDisplay, SLOT (setTimerConnect ()));

    *************************************************************************
    Qt :: WindowFlags flags = 0;
    // Makes the Pomodoro stay on the top of all windows.
    flags |= Qt :: Window | Qt :: WindowStaysOnTopHint;
    // Removes minimize, maximize, and close buttons.
    flags |= Qt :: WindowTitleHint | Qt :: CustomizeWindowHint;
    window->setWindowFlags (flags);
    *************************************************************************
    window->setWindowTitle   ("Failing to plan is planning to fail");

    QGridLayout *layout = new QGridLayout();
    centralWidget->setLayout(layout);

    //Add Items to QGridLayout Here 
    //Row and Column counts are set Automatically
    layout->addWidget (objLcdDisplay, 0, 1);
    layout->addWidget (startButton, 1, 1);
    layout->addWidget (timeIntervalList, 0, 0);

    window->setCentralWidget (centralWidget);
    window->show();

    return app.exec();
}
\ifndef LCDNUMBER\u H
#定义LCDNUMBER_H
#包括
#包括
#包括
#包括
#包括
#包括
lcdDisplay类:公共QLCDNumber
{
Q_对象
公众:
//QTimer类提供重复和单次触发计时器。
QTimer*objTimer;
//QTime类提供时钟时间函数。
QTime*objTime;
公众:
lcdDisplay(QWidget*parentWidget)
{
objTimer=新的QTimer();
//使用指定的小时、分钟和秒设置我们自己的时间。
objTime=新的QTime(0,0,0);
setParent(parentWidget);
};
~lcdDisplay(){};
公众时段:
//此插槽在计时器超时(1秒)后调用。
void setDisplay()
{
//待办事项
objTime->setHMS(0,objTime->addSecs(-1).minute(),objTime->addSecs(-1.second());
显示(objTime->toString());
如果((对象时间->分钟()=0)和(&(对象时间->秒()=0))
{
objTimer->stop();
QMessageBox-msgBox;
msgBox.setWindowTitle(“Pomodoro”);
msgBox.setText(“时间到了”);
setWindowModality(Qt::ApplicationModel);
msgBox.exec();
}
};
无效接收时间间隔(QListWidgetItem*item)
{
QString h=项目->文本();
objTime->setHMS(0,h.toUInt(),0);
}
void setTimerConnection()
{
//连接(objectA、signalAFromObjectA、objectB、slotAFromObjectB)
//timeout():当计时器超时时,会发出此信号。超时时间可以通过'start(int毫秒)`函数指定。
连接(对象计时器,信号(超时()),这个,插槽(setDisplay());
//1秒有1000毫秒。
//开始(int毫秒):以指定毫秒的超时间隔启动计时器。这意味着在1秒后计时器将发出信号。TODO placement
对象计时器->启动(1000);
}
};
#恩迪夫

我目前在没有Qt环境的情况下工作,因此无法测试它。你能试试这个吗

#ifndef  LCDNUMBER_H
#define LCDNUMBER_H

#include <QLCDNumber>
#include <QTimer>
#include <QTime>
#include <QListWidget>
#include <QMessageBox>
#include <iostream>

class lcdDisplay : public QLCDNumber
{
    Q_OBJECT  

    public:
        // The QTimer class provides repetitive and single-shot timers.
        QTimer* objTimer;
        // The QTime class provides clock time functions.
        QTime*  objTime;

    public:
        lcdDisplay (QWidget *parentWidget)
        {
            objTimer = new QTimer ();
            // Setting our own time with the specified hours, minutes, and seconds.
            objTime  = new QTime  (0, 0, 0);

            setParent (parentWidget);
        };

        ~ lcdDisplay () {};

    public slots:
        // This slot is called after the timer timeouts (1 second).
        void setDisplay ()
        {
            // TODO
            objTime->setHMS (0, objTime->addSecs (-1).minute (), objTime->addSecs (-1).second ());
            display (objTime->toString ());

            if ((objTime->minute () == 0) && (objTime->second () == 0)) 
            {
                objTimer->stop ();
                QMessageBox msgBox;
                msgBox.setWindowTitle ("Pomodoro");
                msgBox.setText ("Time's up.");
                msgBox.setWindowModality(Qt::ApplicationModal);
                msgBox.exec();
            }
        };

        void receiveTimeInterval (QListWidgetItem *item)
        {
            QString h = item->text();
            objTime->setHMS (0, h.toUInt(), 0);
        }

        void setTimerConnect ()
        {
            // connect (objectA, signalAFromObjectA, objectB, slotAFromObjectB)
            // timeout (): This signal is emitted when the timer times out. The time out period can be specified with `start (int milliseconds)` function.
            QObject :: connect (objTimer, SIGNAL (timeout ()), this, SLOT (setDisplay ()));

            // 1 second has 1000 milliseconds.
            // start (int milliseconds): Starts the timer with a timeout interval of specified milliseconds. this means that after 1 second the timer will emit a signal. TODO placement
            objTimer->start (1000);
        }
};
#endif

尝试从设置Qt::Dialog开始

Qt::WindowFlags flags = 0;

// Makes the Pomodoro stay on the top of all windows.
flags |= Qt :: WindowStaysOnTopHint;

// Removes minimize, maximize, and close buttons.
flags |= Qt :: WindowTitleHint | Qt :: CustomizeWindowHint;

window->setWindowFlags (flags & ~Qt::WindowSystemMenuHint);
window->setWindowTitle ("Failing to plan is planning to fail");

这对我有用:

setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowStaysOnTopHint);


有时,您必须在窗口的构造函数中指定这些参数,以使其生效。如果您以后分配它们(
setWindowFlags
),某些设置可能不适用。

对不起:(没有帮助。菜单仍然在那里。好的,我会在家里看一下。好的,我检查了它,对我来说,它的工作原理与你在问题中发布的一样。你的窗口的基类是什么?你能提供完整的代码以便我可以在我的计算机上测试它吗?你在Windows上吗?我在Linux上。这只是将窗口移到了屏幕的中心,没有对菜单执行任何操作:(
Qt::Window | Qt::WindowTitleHint | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint