<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Qyoto 介紹 > 原文: [http://zetcode.com/gui/csharpqyoto/introduction/](http://zetcode.com/gui/csharpqyoto/introduction/) 在 Qyoto C# 編程教程的這一部分中,我們將介紹并構建 Qyoto 庫。 我們使用 C# 編程語言創建第一個 Qyoto 程序。 本教程的目的是幫助您開始使用 Qyoto 和 C# 。 可以在此處下載本教程中使用的圖像。 我使用了 Gnome 項目的探戈圖標包中的一些圖標。 該教程是在 Qyoto 項目的維護者 Dimitar Dobrev 的幫助下創建的。 ## 關于 Qyoto 是一個庫,它提供 Qt 庫與.NET 語言(如 C# 或 Visual Basic)的綁定。 Qt 是功能強大的跨平臺應用開發框架。 它的母語是 C++ 。 Qyoto 是 KDE 桌面環境的一部分。 Qyoto 是使用`SMOKE`庫創建的。 這是一個 KDE 項目,用于創建多種語言的綁定。 SMOKE 代表腳本元對象 Kompiler 引擎。 ## 在 Linux 上構建 Qyoto 我們從最新資源構建 Qyoto 庫。 ```cs $ git clone git://anongit.kde.org/smokegen $ git clone git://anongit.kde.org/smokeqt $ git clone git://anongit.kde.org/assemblygen ``` 我們從 git 倉庫下載源代碼。 ```cs $ sudo apt-get install cmake-qt-gui ``` 如果不存在,請安裝`cmake-qt-gui`。 我們按以下順序構建三個包:1)`smokegen`,2)`smokeqt` 和 3)`assemblygen`。 我們在三個目錄中的每個目錄中運行`cmake-qt-gui`。 我們指定源,構建目錄,并將`CMAKE_BUILD_TYPE`設置為`Release`。 我們單擊配置和生成按鈕。 將目錄更改為構建目錄。 運行`make`和`sudo make install`。 ```cs $ export LD_LIBRARY_PATH=/usr/local/qt4/lib ``` 在構建`smokeqt`包之前,我們設置一個環境變量。 每次構建后,我們運行`sudo ldconfig`命令。 ```cs $ ls /usr/local/lib/mono/qyoto qyoto-qtcore.dll qyoto-qtsvg.dll qtscript.dll qyoto-qtgui.dll qyoto-qtuitools.dll qttest.dll qyoto-qtnetwork.dll qyoto-qtwebkit.dll qtuitools.dll qyoto-qtopengl.dll qyoto-qtxml.dll qtwebkit.dll qyoto-qtscript.dll qyoto-qtxmlpatterns.dll qyoto-phonon.dll qyoto-qtsql.dll ``` 我們在`/usr/local/lib/mono/qyoto`目錄中有 Qyoto dll。 ```cs $ dmcs -r:/usr/local/lib/mono/qyoto/qyoto-qtcore.dll \ > -r:/usr/local/lib/mono/qyoto/qyoto-qtgui.dll donut.cs ``` 上面的命令顯示了如何編譯甜甜圈示例。 mono C# 編譯器的`-r`參數加載 Qt 程序集。 這是一個動態庫。 該命令顯示 Linux 系統上 dll 庫的路徑。 ## 創建工具提示 第一個示例將顯示一個工具提示。 工具提示是一個小的矩形窗口,它提供有關對象的簡短信息。 它通常是一個 GUI 組件。 它是應用幫助系統的一部分。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program displays a * tooltip. * * @author Jan Bodnar * website zetcode.com * last modified October 2012 */ public class QyotoApp : QWidget { public QyotoApp() { WindowTitle = "Tooltip"; ToolTip = "This is QWidget"; Resize(250, 150); Move(300, 300); Show(); } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 該示例創建一個窗口。 如果將鼠標指針懸停在窗口區域上方,則會彈出一個工具提示。 ```cs using System; using QtCore; using QtGui; ``` `using`關鍵字導入我們將在應用中使用的必需品類型。 ```cs public class QyotoApp : QWidget { ``` 該示例繼承自`QWidget`。 QWidget 類是所有用戶界面對象的基類。 小部件是用戶界面的原子。 它從窗口系統接收鼠標,鍵盤和其他事件。 ```cs WindowTitle = "Tooltip"; ``` 設置`WindowType`屬性將顯示窗口的標題。 ```cs ToolTip = "This is QWidget"; ``` 我們通過`ToolTip`屬性設置工具提示。 ```cs Resize(250, 150); ``` 在這里,我們設置窗口的寬度和高度。 ```cs Move(300, 300); ``` `Move()`方法在屏幕上移動窗口。 ```cs Show(); ``` 一切準備就緒后,我們在屏幕上顯示窗口。 ```cs [STAThread] public static int Main(String[] args) ``` Windows 平臺上需要`[STAThread]`屬性。 確保與 COM 組件的通信是安全的。 在某些情況下,例如剪貼板和文件對話框,我們正在調用 COM 組件。 沒有此屬性,應用將崩潰。 ```cs new QApplication(args); new QyotoApp(); return QApplication.Exec(); ``` 這三行設置了應用。 ![Tooltip](https://img.kancloud.cn/ea/46/ea466cd1473cc656d3e181fda34ea9ce_252x176.jpg) 圖:工具提示 ## 使窗口居中 在第二個示例中,我們將窗口置于屏幕中央。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program centers a window * on the screen. * * @author Jan Bodnar * website zetcode.com * last modified October 2012 */ public class QyotoApp : QWidget { const int WIDTH = 250; const int HEIGHT = 150; public QyotoApp() { WindowTitle = "Center"; Resize(WIDTH, HEIGHT); Center(); Show(); } private void Center() { QDesktopWidget qdw = new QDesktopWidget(); int screenWidth = qdw.Width; int screenHeight = qdw.Height; int cx = (screenWidth - WIDTH) / 2; int cy = (screenHeight - HEIGHT) / 2; Move(cx, cy); } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` Qyoto 沒有使窗口居中的單一方法。 ```cs const int WIDTH = 250; const int HEIGHT = 150; ``` 這兩個常數定義了應用窗口的寬度和高度。 ```cs Center(); ``` 使窗口居中的代碼位于`Center()`方法中。 ```cs QDesktopWidget qdw = new QDesktopWidget(); ``` `QDesktopWidget`類提供有關屏幕的信息。 ```cs int screenWidth = qdw.Width(); int screenHeight = qdw.Height(); ``` 在這里,我們確定屏幕的寬度和高度。 ```cs int cx = (screenWidth - WIDTH) / 2; int cy = (screenHeight - HEIGHT) / 2; ``` 在這里,我們計算居中窗口的 x,y 坐標。 為了使窗口在屏幕上居中,我們需要知道屏幕的大小和窗口的大小。 ```cs Move(cx, cy); ``` 我們將窗口移至計算出的`cx`,`cy`坐標。 ## 退出按鈕 在本節的最后一個示例中,我們將創建一個退出按鈕。 當我們按下此按鈕時,應用終止。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program creates a quit * button. When we press the button, * the application terminates. * * @author Jan Bodnar * website zetcode.com * last modified October 2012 */ public class QyotoApp : QWidget { public QyotoApp() { WindowTitle = "Quit button"; InitUI(); Resize(250, 150); Move(300, 300); Show(); } public void InitUI() { QPushButton quit = new QPushButton("Quit", this); Connect(quit, SIGNAL("clicked()"), qApp, SLOT("quit()")); quit.SetGeometry(50, 40, 80, 30); } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 我們使用`QPushButton`。 它是矩形的,通常顯示一個文本標簽。 ```cs InitUI(); ``` 我們將用戶界面的創建委托給`InitUI()`方法。 ```cs QPushButton quit = new QPushButton("Quit", this); ``` 我們創建按鈕小部件。 構造器的第一個參數是標簽,按鈕將顯示該標簽。 第二個參數是按鈕的父窗口小部件。 ```cs Connect(quit, SIGNAL("clicked()"), qApp, SLOT("quit()")); ``` 當我們點擊按鈕時,會發出`clicked()`信號。 `Connect()`方法將信號連接到對象的特定槽。 該方法的第一個參數是接收信號的對象。 在我們的例子中,它是應用對象。 第二個參數是方法,稱為。 在我們的情況下,它是應用對象的`quit()`方法。 `qApp`是對應用對象的全局引用。 ```cs quit.SetGeometry(50, 40, 80, 30); ``` 我們定位和調整按鈕小部件的大小。 前兩個參數是按鈕的 x,y 坐標。 最后兩個參數是按鈕的寬度和高度。 ![Quit button](https://img.kancloud.cn/f0/cf/f0cf3c9d90e4b2116ce86cd90a066eea_252x176.jpg) 圖:退出按鈕 本節介紹了使用 C# 語言編寫的 Qyoto 庫。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看