1

pyQt(具体的にはAnki)を使用して作成されたプログラムを変更しようとしています。プログラムで画像を短時間フラッシュして(ハードドライブにファイルとして保存)、通常どおり実行し続けたい。

このコードは、プログラムの任意の場所に挿入されます。これは、既存のプログラムに対するアドホックなシングルユーザーパッチです。高速でエレガントである必要はなく、保守も簡単です。

私の問題は、pyQtについてほとんど知らないということです。まったく新しい「ウィンドウ」を定義する必要がありますか、それともその中に画像を入れてある種の「通知」関数を実行するだけでいいですか?

4

1 に答える 1

5

これには QSplashScreen が役立ちます。プログラムのロード中に特定の画像/テキストを表示するために主に使用されますが、あなたのケースもこれに理想的です。クリックして閉じるか、タイマーを設定して一定時間後に自動的に閉じることができます。

ボタンが 1 つあるダイアログの簡単な例を次に示します。押すと画像が表示され、2 秒後に閉じます。

import sys
from PyQt4 import QtGui, QtCore

class Dialog(QtGui.QDialog):
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)

        self.b1 = QtGui.QPushButton('flash splash')
        self.b1.clicked.connect(self.flashSplash)

        layout.addWidget(self.b1)

    def flashSplash(self):
        # Be sure to keep a reference to the SplashScreen
        # otherwise it'll be garbage collected
        # That's why there is 'self.' in front of the name
        self.splash = QtGui.QSplashScreen(QtGui.QPixmap('/path/to/image.jpg'))

        # SplashScreen will be in the center of the screen by default.
        # You can move it to a certain place if you want.
        # self.splash.move(10,10)

        self.splash.show()

        # Close the SplashScreen after 2 secs (2000 ms)
        QtCore.QTimer.singleShot(2000, self.splash.close)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    main = Dialog()
    main.show()

    sys.exit(app.exec_())
于 2012-09-11T17:51:49.887 に答える