Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 82f71ac

Browse files
author
mttwc
committed
Demonstrates a simple menu bar
1 parent 98028b3 commit 82f71ac

File tree

6 files changed

+40
-63
lines changed

6 files changed

+40
-63
lines changed

HelloQt.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
QT += widgets
77

88
SOURCES = src/main.cpp \
9-
src/plus_minus_demonstration.cpp \
9+
src/simple_menu_demonstration.cpp \
1010

11-
HEADERS = src/plus_minus_demonstration.h
11+
HEADERS = src/simple_menu_demonstration.h
1212

1313
CONFIG -= app_bundle
1414

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include <QApplication>
22
#include <QWidget>
3-
#include "plus_minus_demonstration.h"
3+
#include "simple_menu_demonstration.h"
44

55
int main(int argc, char *argv[])
66
{
77
QApplication app(argc, argv);
88

9-
PlusMinusDemonstration window;
9+
SimpleMenuDemonstration window;
1010

1111
window.resize(250, 150);
12-
window.setWindowTitle("PlusMinus Demonstration");
12+
window.setWindowTitle("SimpleMenu Demonstration");
1313
window.show();
1414

1515
return app.exec();

src/plus_minus_demonstration.cpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/plus_minus_demonstration.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/simple_menu_demonstration.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "simple_menu_demonstration.h"
2+
#include <QAction>
3+
#include <QMenu>
4+
#include <QMenuBar>
5+
6+
SimpleMenuDemonstration::SimpleMenuDemonstration(QWidget *parent)
7+
: QMainWindow(parent)
8+
{
9+
// The ampersand denotes the shortcut
10+
QAction *quit = new QAction("&Quit", this);
11+
12+
// Necessary for OSX because I can't get the menu bar to appear (seems like an old qt bug)
13+
menuBar()->setNativeMenuBar(false);
14+
15+
QMenu *file;
16+
file = menuBar()->addMenu("&File");
17+
file->addAction(quit);
18+
19+
// Note the signal is from the QAction class and the slot is from the QApplication class, which matches the widgets (1st and 3rd params)
20+
connect(quit, &QAction::triggered, qApp, QApplication::quit);
21+
}

src/simple_menu_demonstration.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef SIMPLE_MENU_DEMONSTRATION_H
2+
#define SIMPLE_MENU_DEMONSTRATION_H
3+
4+
#include <QApplication>
5+
#include <QMainWindow>
6+
#include <QWidget>
7+
8+
class SimpleMenuDemonstration : public QMainWindow
9+
{
10+
public:
11+
SimpleMenuDemonstration(QWidget *parent = 0);
12+
};
13+
14+
#endif

0 commit comments

Comments
 (0)