Как убрать меню по умолчанию в левой части строки заголовка - Qt? - PullRequest
3 голосов
/ 15 февраля 2012
    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");

Удаляет кнопки свертывания, разворачивания и закрытия.Меню по умолчанию слева все еще там.Как избавиться от этого?

Я хочу, чтобы строка заголовка была там, но просто хочу, чтобы меню было удалено.

Меню по умолчанию содержит параметры «Свернуть», «Развернуть», «Переместить» и т. Д.

РЕДАКТ. 1:

timer.cpp

#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();
}

Timer.h

#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

Ответы [ 3 ]

3 голосов
/ 15 февраля 2012

Это работает для меня:

Qt::Window | Qt::WindowTitleHint | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint

Screen shot

Иногда вам нужно указать их в конструкторе окна, чтобы они вступили в силу.Если вы назначите их позже (setWindowFlags), некоторые настройки могут не применяться.

0 голосов
/ 15 февраля 2012

Попробуйте начать с установки Qt :: Dialog

setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowStaysOnTopHint);
0 голосов
/ 15 февраля 2012

В настоящее время я нахожусь на работе без среды Qt, поэтому я не смог ее протестировать.Не могли бы вы попробовать это?

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");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...