📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)

文字列「__FORCETOC__」を「{{#seo: |title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki |keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 |description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This pag…
 
(同じ利用者による、間の4版が非表示)
4行目: 4行目:


== タイトルバー ==
== タイトルバー ==
==== アイコン ====
ウインドウのタイトルバーにアイコンを指定するには、<code>setWindowIcon</code>メソッドを使用する。<br>
ウインドウのタイトルバーにアイコンを指定するには、<code>setWindowIcon</code>メソッドを使用する。<br>
<center>
<center>
{| class="wikitable" style="background-color:#fefefe;"
{| class="wikitable" style="background-color:#fefefe;"
|-
|-
! style="background-color:#00ffff;" | データ  
! style="background-color:#66CCFF;" | データ  
! style="background-color:#00ffff;" | アイコンの設定例(QIconクラス)
! style="background-color:#66CCFF;" | アイコンの設定例(QIconクラス)
|-
|-
| 標準画像 || QIcon Icon = style()->standardIcon(QStyle::SP_MediaPlay);<br>setWindowIcon(Icon);
| style="text-align: center;" | 標準画像 ||  
<syntaxhighlight lang="c++">QIcon Icon = style()->standardIcon(QStyle::SP_MediaPlay);
QApplication::setWindowIcon(Icon);</syntaxhighlight>
|-
|-
| 標準カーソル || QCursor Cursor = Qt::WaitCursor;<br>if(!Cursor.pixmap().isNull())<br>{<br>  QIcon Icon = QIcon(QPixmap(csr.pixmap()));<br>  setWindowIcon(Icon);<br>}
| style="text-align: center;" | 標準カーソル ||
<syntaxhighlight lang="c++">QCursor Cursor = Qt::WaitCursor;
if(!Cursor.pixmap().isNull())
{
  QIcon Icon = QIcon(QPixmap(csr.pixmap()));
  QApplication::setWindowIcon(Icon);
}
</syntaxhighlight>
|-
|-
| リソース || QIcon Icon = QIcon(":/images/mouse.png");<br>setWindowIcon(Icon);
| style="text-align: center;" | リソースの指定 ||
<syntaxhighlight lang="c++">
QIcon Icon = QIcon(":/images/mouse.png");
QApplication::setWindowIcon(Icon);
</syntaxhighlight>
|-
|-
| ファイル || QIcon Icon = QIcon("C:/temp/testimage.ico");<br>setWindowIcon(Icon);
| style="text-align: center;" | ファイルパスの指定 ||
<syntaxhighlight lang="c++">
QIcon Icon = QIcon("C:/temp/testimage.ico");
QApplication::setWindowIcon(Icon);
</syntaxhighlight>
|}
|}
</center>
</center>
<br>
==== タイトルバーの非表示 ====
<code>setWindowFlags</code>メソッドを使用して、<code>Qt::FramelessWindowHint</code>フラグを設定することにより、ウインドウのタイトルバーが非表示になる。<br>
この<code>Qt::FramelessWindowHint</code>フラグを使用すると、最大化/最小化ボタン、ウインドウの境界線、タイトルバーが非表示になる。<br>
<br>
したがって、このフラグを使用することにより、ウインドウ全体がカスタム外観になり、デフォルトのウインドウ機能が失われる。<br>
また、必要に応じて、これらの機能を再実装することもできる。<br>
<syntaxhighlight lang="c++">
#include <QGUIApplication>
#include <QMainwindow>
int main(int argc, char *argv[])
{
    QGUIApplication a(argc, argv);
    QMainWindow Window;
    // タイトルバーを非表示にする
    Window.setWindowFlags(Qt::FramelessWindowHint);
    Window.show();
    return a.exec();
}
</syntaxhighlight>
<br><br>
<br><br>


223行目: 266行目:
  {
  {
     widget->setTabOrder(widget, widget);
     widget->setTabOrder(widget, widget);
}
</syntaxhighlight>
<br><br>
== イベント ==
==== リサイズイベント ====
<code>resizeEvent</code>メソッドは、ウィジェットのサイズが変化した時に発生する。<br>
<syntaxhighlight lang="c++">
// Mainwindow.h
// ... 略
protected:
    void resizeEvent(QResizeEvent *event);
</syntaxhighlight>
<br>
<syntaxhighlight lang="c++">
// Mainwindow.cpp
// ウインドウの幅と高さをデバッグ出力する
void MainWindow::resizeEvent(QResizeEvent *event)
{
    qDebug("Resize old=%dx%d,new=%dx%d", event->oldSize().width(), event->oldSize().height(), event->size().width(), event->size().height() );
}
</syntaxhighlight>
<br>
==== クローズイベント ====
<code>closeEvent</code>メソッドは、タイトルバーの×ボタンを押下した時やcloseメソッドを実行する時に発生する。<br>
<syntaxhighlight lang="c++">
// Mainwindow.h
// ...略
protected:
    void closeEvent(QCloseEvent *event);
private:
    bool checkQuit;
</syntaxhighlight>
<br>
コンストラクタでスイッチ(変数checkQuit)を初期化する。<br>
スイッチをtrueにする時、ウインドウを閉じる直前に確認メッセージのYes / Noメッセージボックスを表示する。<br>
Noを選択する場合、終了処理を行わずに元の画面に戻る。<br>
Yesを選択する場合、ウインドウを閉じて終了する。<br>
<syntaxhighlight lang="c++">
// Mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    checkQuit = true;
}
</syntaxhighlight>
<br>
<syntaxhighlight lang="c++">
// Mainwindow.cpp
void MainWindow::closeEvent(QCloseEvent *event)
{
    if(checkQuit)
    {
      int ret = QMessageBox::question(this, tr("終了確認"), tr("終了しますか?"));
      if(ret == QMessageBox::No)
      {
          event->ignore();
      }
    }
    event->accept();
  }
  }
  </syntaxhighlight>
  </syntaxhighlight>
272行目: 380行目:
QSSの書式や構文は、CSSとほぼ同じである。<br>
QSSの書式や構文は、CSSとほぼ同じである。<br>
<br>
<br>
以下の例は、Qtに付属しているサンプルを参考にしている。(<Qtのインストールディレクトリ>/examples/widgets/stylesheetディレクトリ)<br>
以下の例は、Qtに付属しているサンプルを参考にしている。<br>
(<Qtのインストールディレクトリ>/Examples/Qt-<バージョン名>/widgets/widgets/stylesheetディレクトリ)<br>
まず、MainWindow.qssファイルを作成する。<br>
まず、MainWindow.qssファイルを作成する。<br>
  <syntaxhighlight lang="css">
  <syntaxhighlight lang="css">
324行目: 433行目:
  </syntaxhighlight>
  </syntaxhighlight>
<br>
<br>
==== ウィンドウの背景を画像にする ====
==== ウィンドウの背景を画像にする ====
<code>QStyle</code>クラスは、ウィンドウの外見を詳細に設定することができる。<br>
<code>QStyle</code>クラスは、ウィンドウの外見を詳細に設定することができる。<br>
330行目: 440行目:
<code>QStyle</code>クラスを継承した派生クラスは数種類用意されており、OSにより使用できるものが決まっている。<br>
<code>QStyle</code>クラスを継承した派生クラスは数種類用意されており、OSにより使用できるものが決まっている。<br>
<br>
<br>
以下の例は、Qtに付属しているサンプルを参考にしている。(<Qtのインストールディレクトリ>/examples/widgets/stylesheetディレクトリ)<br>
以下の例は、<code>QStyle</code>クラスを継承した派生クラスを作成している。<br>
ここでは、examples/widgets/stylesディレクトリに合わせて、<code>QMotifStyle</code>クラスを継承した派生クラスを作成している。<br>
<br>
<br>
設定後、<code>QMainWindow</code>クラスまたは<code>QDialog</code>クラスのコンストラクタにおいて、以下のように記述して適用する。<br>
設定後、<code>QMainWindow</code>クラスまたは<code>QDialog</code>クラスのコンストラクタにおいて、以下のように記述して適用する。<br>
  <syntaxhighlight lang="c++">
  <syntaxhighlight lang="c++">
  QApplication::setStyle(new MyStyle);  // MyStyleクラスは、QMotifStyleクラスの派生クラス
  QApplication::setStyle(new MyStyle);  // MyStyleクラスは、QStyleクラスの派生クラス
  </syntaxhighlight>
  </syntaxhighlight>
<br>
<br>
343行目: 452行目:
  #pragma once
  #pragma once
   
   
  #include <QtGui/QMotifStyle>
  #include <QStyle>
   
   
  class MyStyle : public QMotifStyle
  class MyStyle : public QStyle
  {
  {
  public:
  public:
378行目: 487行目:
  </syntaxhighlight>
  </syntaxhighlight>
<br>
<br>
==== ボタンのスタイルの変更 ====
==== ボタンのスタイルの変更 ====
上記のセクションにも記述した<code>polish</code>メソッドを使用して、ボタンのスタイルを変更することができる。<br>
上記のセクションにも記述した<code>polish</code>メソッドを使用して、ボタンのスタイルを変更することができる。<br>
542行目: 652行目:
  </syntaxhighlight>
  </syntaxhighlight>
<br><br>
<br><br>
{{#seo:
|title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki
|keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板
|description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This page is {{PAGENAME}} in our wiki about electronic circuits and SUSE Linux
|image=/resources/assets/MochiuLogo_Single_Blue.png
}}


__FORCETOC__
__FORCETOC__
[[カテゴリ:Qt]]
[[カテゴリ:Qt]]