翻譯|使用教程|編輯:龔雪|2023-06-02 11:06:16.320|閱讀 164 次
概述:本文將為大家介紹Qt框架中的Dir視圖使用實例,歡迎下載相關(guān)組件體驗~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Qt 是目前最先進、最完整的跨平臺C++開發(fā)工具。它不僅完全實現(xiàn)了一次編寫,所有平臺無差別運行,更提供了幾乎所有開發(fā)過程中需要用到的工具。如今,Qt已被運用于超過70個行業(yè)、數(shù)千家企業(yè),支持數(shù)百萬設(shè)備及應(yīng)用。
Qt技術(shù)交流群:166830288 歡迎一起進群討論
本示例演示了樹形視圖的用法,以及在觸摸屏上的平滑滑動。
Dir視圖示例展示了本地文件系統(tǒng)的樹視圖,它使用 類來提供文件和目錄信息。
QCommandLineParser parser; parser.setApplicationDescription("Qt Dir View Example"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons"); parser.addOption(dontUseCustomDirectoryIconsOption); QCommandLineOption dontWatchOption("w", "Set QFileSystemModel::DontWatch"); parser.addOption(dontWatchOption); parser.addPositionalArgument("directory", "The directory to start in."); parser.process(app); const QString rootPath = parser.positionalArguments().isEmpty()
本示例支持許多命令行選項,這些選項包括:
QFileSystemModel model; QFileIconProvider iconProvider; model.setIconProvider(&iconProvider); model.setRootPath(""); if (parser.isSet(dontUseCustomDirectoryIconsOption)) model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons); if (parser.isSet(dontWatchOption)) model.setOption(QFileSystemModel::DontWatchForChanges); QTreeView tree; tree.setModel(&model);
將model聲明為讀取本地文件系統(tǒng)的數(shù)據(jù)模型,setrootpath("")將當前文件夾設(shè)置為模型將開始讀取的文件夾,QTreeView對象樹以樹狀結(jié)構(gòu)可視化文件系統(tǒng)。
tree.setAnimated(false); tree.setIndentation(20); tree.setSortingEnabled(true); const QSize availableSize = tree.screen()->availableGeometry().size(); tree.resize(availableSize / 2); tree.setColumnWidth(0, tree.width() / 3);
設(shè)置文件系統(tǒng)樹的動畫、縮進、排序和大小調(diào)整的布局選項。
QScroller::grabGesture(&tree, QScroller::TouchGesture);
創(chuàng)建一個QScroller實例來識別觸摸屏上的手勢,這樣您就可以用手指輕彈樹視圖。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)