Qt-QMainWindow
发布日期:2021-05-10 12:51:03 浏览次数:18 分类:精选文章

本文共 3572 字,大约阅读时间需要 11 分钟。

Qt-QMainWindow ������������������

QMainWindow ������ Qt ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������

������������ Qt ������������������������������������������������������������������ menuBar() ��������������������������������������������������� addMenu() ������������������������������������������������

QMenu *fileMenu = menuBar()->addMenu("file"); // ������������������

������������������������������������ QAction ��������������� QAction ���������������������������������������������������������������������������������������������������������������������������������

QAction *fileOpenAction = new QAction("open", this);
fileOpenAction->setShortcut(tr("Ctrl+O"));
fileOpenAction->setToolTip("������������");
fileMenu->addAction(fileOpenAction);
fileMenu->addSeparator(); // ���������������

���������������������������������������������������������������������������������open.png��� ���������������������open���������������������������������������������������������

���������

��������������������������������������������������������������������������������������������� addToolBar() ��������������������������������� QAction ��������������� widget ������������������������

QToolBar *fileBar = addToolBar("file");
fileBar->addAction(fileOpenAction);

��������������������� QAction������������������������ widget���������������������������������������������������������

���������

������������������������������������������������������������������������ statusBar() ��������������������������������� addWidget() ������������������������������������������

QLabel *statusLabel = new QLabel("������");
statusBar()->addWidget(statusLabel);

������������������������������������������ showMessage() ���������������������������������������������������������������������������������������������������������������������������

������������

��������������������������������������������������������������������������� setCentralWidget() ��������������������������������������� edit ������������������������ TextEdit ���������

QTextEdit *mainEdit = new QTextEdit;
setCentralWidget(mainEdit);

������������������������������ QHBoxLayout ���������������������������������������������������

QHBoxLayout *mainLayout = new QHBoxLayout;
setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(mainEdit);
setCentralWidget(mainLayout);

������������

#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) {
setWindowTitle("MainWindow");
// ������ QAction
fileOpenAction = new QAction("open", this);
fileOpenAction->setShortcut("Ctrl+O");
fileOpenAction->setToolTip("������������");
connect(fileOpenAction, SIGNAL(triggered(bool)), this, SLOT(showOpenFile()));
// ������������
fileMenu = menuBar()->addMenu("file");
fileMenu->addAction(fileOpenAction);
fileMenu->addSeparator();
// ���������������
fileToolBar = addToolBar("file");
fileToolBar->addAction(fileOpenAction);
// ������������������
mainEdit = new QTextEdit;
setCentralWidget(mainEdit);
// ���������������
statusLabel = new QLabel;
}
MainWindow::~MainWindow() {}
void MainWindow::showOpenFile() {
statusBar()->showMessage("hello", 3000);
}

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:Linux下的一些实用的工具
下一篇:Python基本文件操作

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月08日 12时24分18秒