私はRuby内で(QtRubyを介して)Qt 4.6を使用しており、ファイルシステムが照会され、ディレクトリツリー(QTreeView)が更新されている間、小さな「読み込み中」のグリフを表示する一般的なディレクトリ選択ダイアログを作成しようとしています。
更新:アニメーションが期待どおりに機能しないと言わなければなりませんが、これらのイベント(読み込み中、読み込み中)を検出する別の方法はありますか?以下の「別の注意事項」を参照してください。
rowsInserted
使用したQFileSystemModelのSignalを介して「newdirectoryloaded」イベントに接続できましたが、問題なく動作します。rowsAboutToBeInserted
また、シグナルを介して「新しいディレクトリの読み込み」イベントをキャッチすることもできます。それでも、再生しようとしているアニメーション(QMovie内にロードされた進行状況を示す単純なアニメーションGIF)は、「展開」されたディレクトリが空であっても再生されます。これが私が使用しているコードです:
# FileSystemModel extension which shows a 'busy' animation
# in a given Qt::Label
class FileSystemModelEx < Qt::FileSystemModel
# Slot declarations
slots "handle_ready(QModelIndex, int, int)"
slots "handle_busy(QModelIndex, int, int)"
# Parametrised constructor, initializes fields
def initialize(p_parent, p_label, p_busy_icon, p_ready_icon)
# Call superclass constructor
super(p_parent)
# Set instance vars
@label = p_label
@busy_icon = p_busy_icon
@ready_icon = p_ready_icon
# Connect 'finished loaded' event
Qt::Object.connect(self,
SIGNAL('rowsAboutToBeInserted(QModelIndex, int, int)'),
self,
SLOT('handle_busy(QModelIndex, int, int)'))
# Connect 'loading' event
Qt::Object.connect(self,
SIGNAL('rowsInserted(QModelIndex, int, int)'),
self,
SLOT('handle_ready(QModelIndex, int, int)'))
end
# Loading finished event, changes icon state to ready
def handle_ready(p_index, p_start, p_end)
set_icon(false)
puts " done - loaded #{rowCount(p_index)} folders"
end
# Loading started event, changes icon state to busy
def handle_busy(p_index, p_start, p_end)
set_icon(true)
path = fileInfo(p_index).canonicalFilePath
puts "Loading . . . path = '#{path}'"
end
# Overriden start loading event
def fetchMore(p_index)
handle_busy(p_index, nil, nil)
super(p_index)
end
# Utility method, switches icons, depending on a given state
def set_icon(p_busy)
movie = (p_busy ? @busy_icon : @ready_icon)
@label.setMovie(movie)
movie.start
end
end # class FileSystemModelEx
私の質問は次のようになります:ロードされたフォルダが空の場合、どうすればアニメーションが再生されないようにできますか?空のディレクトリを事前にフィルタリングすることはできませんね。
別の注意点として、上記以外に、このような「ロード」/「ロード」イベントハンドラーを実装する別の方法はありますか?シグナル、仮想(fetchMore
およびcanFetchMore
、役に立たない)を調べ、ソースをスキャンしましたが、さらにファイルを取得するためにスレッドを送信する呼び出しに到達できません。オーバーライドevent
するかtimerEvent
、役に立ちません。
完成させるために、これも私が使用しているQFileSystemModelです。
# Creates a FileSystemModel which display folders only
def create_model
@model = FileSystemModelEx.new(self,
@form.iconPlaceholderDir,
@loading_icon, @folder_icon)
@model.setReadOnly(true)
@model.setFilter(Qt::Dir::NoDotAndDotDot | Qt::Dir::AllDirs)
@model.setRootPath(Qt::Dir.rootPath)
@form.shellTreeView.setModel(@model)
end
よろしくお願いします。必要に応じて、問題なく詳細をお知らせします。