Pregunta

Estoy usando una costumbre subclase QFileSystemModel en una vista de árbol para permitir a los usuarios seleccionar carpetas usando casillas de verificación. Mi problema es que las unidades de red mapeadas se muestran como unidades de disco duro, pero no puede operar en ellos, así que quiero sólo para mostrar las unidades locales. ¿Cómo puedo forzar QFileSystemModel para mostrar sólo las unidades locales?

¿Fue útil?

Solución

From what I've been able to figure out from sources and docs, it is impossible to do directly with QFileSystemModel.

The only possible workaround I can think of is to use a QSortFilterProxyModel subclass with redefined filterAcceptsRow() or filterAcceptsColumn() or both, I'm not sure which one as I haven't used QFileSystemModel and don't know what it considers columns and what rows. The redefined method would then figure out the path of the file possibly by using data() with QFileSystemModel::FilePathRole or by using qobject_cast<> and calling QFileSystemModel::filePath(). Then it would somehow figure out the root path of a drive and call GetDriveType() WinAPI function as Qt apparently provides no way to figure out whether a drive is network or not. Of course, this stuff has to be put under #ifdef Q_OS_WIN32.

This looks complicated, but I can think of no other way. I'm also not sure how fast GetDriveType() is, but if there are performance problems it is always possible to implement some kind of caching.

Otros consejos

How about using QFileSystemModel filter to only QDir::Drives. To my knowledge, this lists only the local hard drives.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top