4月 12, 2011 by 鈴木 佑 | Comments
この記事は Qt Blog の "Mac Toolbars for Qt Quick" を翻訳したものです。
執筆: Morten Johan Sørvig 2011年4月8日
以前に Jens が書いたとおり、デスクトップでも Qt Quick を使用できるように作業をしています。彼がその記事のコメントの中で明かしたように、私は Mac 向けのプロジェクトを進めています。今日はこれについて書きたいと思います。
ツールバーの動作: メニューのカスタマイズは Qt では新しい機能ですが、Mac としては特に目新しいものはありません。
では、今までの Qt でのやり方とは何が違うのでしょう?まず始めに、QToolBar の変わりに NSToolBar が使われています。これにより、(念願のメニューのカスタマイズ機能を含む)ネイティブのルック&フィールが実現されています。次に、このツールバーは以下のように普通の QML の要素と同じように作成することが可能になりました。
MacToolBar {
MacToolButton {
text : "Button 1"
iconSource : "images/qtlogo.png"
toolTip : "This is button number 1"
onActivated : status.text = "Button1 Clicked"
}MacToolButton { standardItem : MacToolButton.ShowColors }
MacToolButton { standardItem : MacToolButton.Space }
}
MacToolBar は QML のシーンには描画されません。その変わりウィンドウに NSToolBar を追加します。
カラーパネルにも同じような書き方でアクセスすることができます。
MacColorPanel {
onColorChanged : { status.color = color; }
}
最後に、C++ でアプリケーションを書く場合に利用可能な QAction ベースのインターフェースもあります。
QWidget *window = ...;
QtMacToolBar * macToolBar = new QtMacToolBar(window);
QAction * fooAction = macToolBar->addAction("FooButton");
QAction * barAction = macToolBar->addAction("BarButton");
macToolBar->showInWindow(window);
これらのコードは qt-components/desktop の "mac" ブランチの中の examples/MacToolbar.qml にあります。
Download the latest release here: www.qt.io/download.
Qt 6.9 is now available, with new features and improvements for application developers and device creators.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
1 24, 2025
本稿は「RectangularShadow: Fast rectangle shadows in Qt 6.9」の抄訳です。..
12 23, 2024
本稿は「Building Your Next Industrial Cockpit with Qt」の抄訳です。..