Qyoto (Qt) を用いて、今回は、設定した範囲の数字を調節するウィジェット 3 種類を紹介します。
まず、Fedora 20 における Mono / Qyoto の開発環境の主要なパッケージですが、前回と同じく以下の通りです。
- mono-core-3.4.0-2.fc20.x86_64
- qt-4.8.6-5.fc20.x86_64
- qyoto-4.12.5-1.fc20.x86_64
- qyoto-devel-4.12.5-1.fc20.x86_64
スピンボックス
スピンボックス QSpinBox は、ボックスに表示されている数値データを,ボックスの右端にあるアップダウンボタンで増減させて変更するウィジェットです。「↑」「↓」キーやマウスホイールでも調節できます。
List: spinbox.cs
using System;
using Qyoto;
/**
* ZetCode Qyoto C# tutorial
*
* This program uses the QSpinBox widget.
* The option selected from the combo box is
* displayed in the label widget.
*
* @author Jan Bodnar
* website zetcode.com
* last modified October 2012
*
* modified by Fujito Suguri
* last modified 7-Jun-2014
*/
public class QyotoApp : QWidget
{
public QyotoApp ()
{
WindowTitle = "スピンボックス";
InitUI ();
Move (100, 100);
Show ();
}
void InitUI ()
{
QSpinBox sp = new QSpinBox ();
sp.SetRange (0, 100);
sp.SetValue(50);
sp.Alignment = (uint) AlignmentFlag.AlignRight;
sp.SetSizePolicy (QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Preferred);
Connect (sp, SIGNAL ("valueChanged(int)"), this, SLOT ("OnValueChanged(int)"));
QVBoxLayout vbox = new QVBoxLayout (this);
vbox.AddWidget (sp);
}
[Q_SLOT]
void OnValueChanged (int i)
{
Console.WriteLine ("値が " + i + " になりました。");
}
[STAThread]
public static int Main (String[] args)
{
new QApplication (args);
new QyotoApp ();
return QApplication.Exec ();
}
}
コンパイルおよび実行例を以下に示します。
$ mcs spinbox.cs -pkg:qyoto $ mono spinbox.exe 値が 51 になりました。 値が 52 になりました。 値が 53 になりました。
スライダー
スライダー QSlider はツマミをマウスでドラッグすることで、値を変更できるウィジェットです。「↑」「↓」キーやマウスホイールでも調節できます。
List: slider.cs
using System;
using Qyoto;
/**
* ZetCode Qyoto C# tutorial
*
* This program uses the QSlider widget.
* The option selected from the combo box is
* displayed in the label widget.
*
* @author Jan Bodnar
* website zetcode.com
* last modified October 2012
*
* modified by Fujito Suguri
* last modified 7-Jun-2014
*/
public class QyotoApp : QWidget
{
public QyotoApp ()
{
WindowTitle = "スライダー";
InitUI ();
Move (100, 100);
Show ();
}
void InitUI ()
{
QSlider sl = new QSlider ();
sl.SetRange (0, 100);
sl.SetValue (50);
sl.SetOrientation (Orientation.Horizontal);
sl.FocusPolicy = FocusPolicy.StrongFocus;
sl.tickPosition = QSlider.TickPosition.TicksBelow;
sl.TickInterval = 10;
sl.SetSizePolicy (QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred);
Connect (sl, SIGNAL ("valueChanged(int)"), this, SLOT ("OnValueChanged(int)"));
QVBoxLayout vbox = new QVBoxLayout (this);
vbox.AddWidget (sl);
}
[Q_SLOT]
void OnValueChanged (int i)
{
Console.WriteLine ("値が " + i + " になりました。");
}
[STAThread]
public static int Main (String[] args)
{
new QApplication (args);
new QyotoApp ();
return QApplication.Exec ();
}
}
コンパイルおよび実行例を以下に示します。
$ mcs slider.cs -pkg:qyoto $ mono slider.exe 値が 51 になりました。 値が 52 になりました。 値が 53 になりました。
ダイヤル †
† 「だいある」で一発変換できなかったのでダイヤルにしました。
ダイヤル QDial は、スライダーと同様にツマミをマウスでドラッグすることで、値を変更できるウィジェットですが直線的ではなく回転的に値を変化させるウィジェットです。「↑」「↓」キーやマウスホイールでも調節できます。
List: dial.cs
using System;
using Qyoto;
/**
* ZetCode Qyoto C# tutorial
*
* This program uses the QDial widget.
* The option selected from the combo box is
* displayed in the label widget.
*
* @author Jan Bodnar
* website zetcode.com
* last modified October 2012
*
* modified by Fujito Suguri
* last modified 7-Jun-2014
*/
public class QyotoApp : QWidget
{
public QyotoApp ()
{
WindowTitle = "ダイヤル";
InitUI ();
Move (100, 100);
Show ();
}
void InitUI ()
{
QDial dl = new QDial ();
dl.SetRange (0, 100);
dl.SetValue (50);
dl.SetNotchesVisible (true);
dl.FocusPolicy = FocusPolicy.StrongFocus;
dl.SetSizePolicy (QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Preferred);
Connect (dl, SIGNAL ("valueChanged(int)"), this, SLOT ("OnValueChanged(int)"));
QVBoxLayout vbox = new QVBoxLayout (this);
vbox.AddWidget (dl);
}
[Q_SLOT]
void OnValueChanged (int i)
{
Console.WriteLine ("値が " + i + " になりました。");
}
[STAThread]
public static int Main (String[] args)
{
new QApplication (args);
new QyotoApp ();
return QApplication.Exec ();
}
}
コンパイルおよび実行例を以下に示します。
$ mcs dial.cs -pkg:qyoto $ mono dial.exe 値が 51 になりました。 値が 52 になりました。 値が 53 になりました。
参考サイト
- C# Qyoto tutorial
- Qyoto: Main Page - Qyoto Documentation





0 件のコメント:
コメントを投稿