| ホーム · All Namespaces · 全てのクラス · 主要なクラス · グループ別クラス · Modules · 関数一覧 |
[前へ: Scribe クラス] [ホーム] [次へ: 新しい Qt Designer]
Qt 4 から新しいメインウインドウクラスが使用可能になりました。これは Qt 3 のメインウインドウクラスと置き換えられるもので、使いやすさはそのままに、より実用的なものとなっています。
顧客および社内の開発者から寄せられた多数の要求を満たすべく、メインウィンドウに関連するクラスは再設計された. その目的としては、メインウィンドウの管理における堅実かつ効率的なフレームワークを提供することにある.
Qt 4 は、メインウィンドウおよび関連するユーザインターフェースコンポーネントの管理のために以下のクラスを提供する:
. QMainWindow は簡単に使うことができます。通常、 QMainWindow をサブクラス化し、メニュー・ツールバー・Dock ウィジェットを QMainWindow コンストラクタで設定します。
メインウインドウにメニューバーを追加する時は、単純にメニューを作成し、メインウインドウのメニューバーに追加するだけです。 Note that the QMainWindow::menuBar() 関数が初めて呼ばれた時、自動的にメニューバーを作成します。 メインウインドウにカスタムメニューバーを使用するときは QMainWindow::setMenuBar() を使うことができます。
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
...
newAct = new QAction(tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Create a new file"));
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
...
"アクション" を作成したら、それらをメインウインドウのコンポーネントに追加できます。ここでは、ポップアップメニューにアクションを追加します。:
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAct);
fileMenu->addAction(openAct);
...
fileMenu->addSeparator();
...
The QToolBar と QMenu classes use Qt's action system to provide a consistent API. In the above code, some existing actions were added to the file menu with the QMenu::addAction() function. QToolBar also provides this function, making it easy to reuse actions in different parts of the main window. This avoids unnecessary duplication of work.
We create a toolbar as a child of the main window, and add the desired actions to it:
fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(newAct);
fileToolBar->addAction(openAct);
...
fileToolbar->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
addToolBar(Qt::TopToolBarArea, fileToolbar);
In this example, the toolbar is restricted to the top and bottom toolbar areas of the main window, and is initially placed in the top tool bar area. We can see that the actions specified by newAct と openAct will be displayed both on the toolbar and in the file menu.
QDockWidget is used in a similar way to QToolBar. We create a dock widget as a child of the main window, and add widgets as children of the dock widget:
contentsWindow = new QDockWidget(tr("Table of Contents"), this);
contentsWindow->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea);
addDockWidget(Qt::LeftDockWidgetArea, contentsWindow);
headingList = new QListWidget(contentsWindow);
contentsWindow->setWidget(headingList);
In this example, the dock widget can only be placed in the left and right dock areas, and it is initially placed in the left dock area.
QMainWindow API allows the programmer to customize which dock widget areas occupy the four corners of the dock widget area. If required, the default can be changed with the QMainWindow::setCorner() function:
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
The following diagram shows the configuration produced by the above code. Note that the left and right dock widgets will occupy the top and bottom corners of the main window in this layout.
Once all of the main window components have been set up, the central widget is created and installed by using code similar to the following:
QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
The central widget can be any subclass of QWidget.
The main window classes in Qt 4 adds new functionality, mainly to the dock widgets and toolbars. We have also made changes to the design of the framework.
Although the QMainWindow class in Qt 3 provided support for toolbars, dock widgets, and other standard user interface components, its design meant that these items were managed through a large number of QMainWindow member functions. In Qt 4, the QMainWindow class delegates many of the management tasks to QDockWidget と QToolBar (allowing more consistent behavior to be defined and implemented).
The dock widget and toolbar classes are now separated into independent classes. (write some more here)
(It is intended that these changes allow more consistent behavior to be defined and implemented (which? example). In response to feedback from customers, we hope to improve these classes even further.)
Dock widgets are animated when docking or detaching from a dock area. The dock areas will also adjust their size to show where the dock widget will dock when it hovers over it. This animation can be turned off with setAnimated()サブクラスならば何でも構わない.
By default, dock widgets are added to the dock areas in a single row. By setting nesting enabled with setDockNestingEnabled(), the widgets can be added both vertically and horizontally.
Two dock widgets can occupy the same space in a dock area. The user can then choose which widget that is visible with a tab bar that is located below the widgets. The QMainWindow::tabifyDockWidget() joins two tab widgets in such a tabbed dock area. (revise the entire paragraph)
Toolbar and dock window functionality is provided by two independent classes: QToolBar と QDockWidget. Toolbars and dock widgets reside in separate areas, with toolbars outside the dock widget area. This behavior differs from the Qt 3 behavior, where QToolBar inherited functionality from QDockWidget, and both types of component shared the same areas. The result is a more consistent and predictable experience for users. Toolbars and dock widgets provide feedback while being dragged into their new positions.
The diagram above shows the layout of a main window that contains both toolbars and dock widgets. Each corner area can be used by either of the adjacent dock widget areas, allowing dock widget behavior and main window layout to be specified precisely.
Toolbars and dock widgets are child widgets of the main window. They are no longer reparented into a dock area widget by the main window. Instead, layouts are used to manage the placement of toolbars and dock widgets. One consequence is that the old QDockArea class is no longer required in Qt 4.
QMainWindow retains the menuBar() function, but menus are always constructed using QAction オブジェクトを使って構築される. 全てのメニューの種類は、包括的な QMenu クラスを使って構築される.
Qt 3:
QPopupMenu *fileMenu = new QPopupMenu(this);
openAction->addTo(fileMenu);
saveAction->addTo(fileMenu);
...
menuBar()->insertItem(tr("&File"), fileMenu);
Qt 4:
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
...
ツールバーの生成はメニューの生成方法と同様に、新しくより一貫性があるようになっている.
Qt 3:
QToolBar *fileTools = new QToolBar(this, "file toolbar");
openAction->addTo(fileTools);
saveAction->addTo(fileTools);
...
Qt 4:
QToolBar *fileTools = addToolBar(tr("File Tool Bar"));
fileTools->addAction(openAction);
fileTools->addAction(saveAction);
...
ドックウィジェットの振る舞いは、 QDockWidgetのメンバ関数を通じて設定されるようになった. 例として、メインウィンドウの左サイドにあるドック領域にドックウィジェットを生成するための新旧の方法を比較してみる.
In Qt 3:
QDockWidget *dockWidget = new QDockWidget(this);
mainWin->moveDockWidget(dockWidget, Qt::DockLeft);
In Qt 4:
QDockWidget *dockWidget = new QDockWidget(mainWindow);
mainWindow->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
[前へ: Scribeクラス] [ホーム] [次へ: 新しい Qt Designer]
| Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.5.0 |