Qt Quick での Mac のツールバー
April 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 にあります。
Blog Topics:
Comments
Subscribe to our newsletter
Subscribe Newsletter
Try Qt 6.5 Now!
Download the latest release here: www.qt.io/download.
Qt 6.5 is the latest Long-Term-Support release with all you need for C++ cross-platform app development.
Explore Qt World
Check our Qt demos and case studies in the virtual Qt World
We're Hiring
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.Henkilön Qt (@theqtcompany) jakama julkaisu