QtableView添加内层Items(多行多列)

雒珣 2019-12-19 10:33:40

各位大神,求助!
我在写一个QT界面模拟windows文件管理界面,文件列表用的是QTreeView和QTableView控件。
现在QtableView不知道该如何添加多列子表,当点击QTreeView时,我希望能进到QTableView相应的子表中,但是不知道怎么添加多列子表,请问只能第一个父表是多列的吗,子表可以是多列的吗?
求教
...全文
993 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LandyTan 2020-01-22
  • 打赏
  • 举报
回复
QTreeView+QFileSystemModel组成View/Model
非弋 2020-01-21
  • 打赏
  • 举报
回复

	Widget::Widget(QWidget *parent)
	{
		QString strRootPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
		
		QFileSystemModel *pFileSystemModel = new QFileSystemModel(this);
		pFileSystemModel->setRootPath(strRootPath);
		
		QFileSystemModel *pDirSystemModel = new QFileSystemModel(this);
		pDirSystemModel->setRootPath(strRootPath);
		pDirSystemModel->setFilter(QDir::AllDirs|QDir::Dirs|QDir::NoDotAndDot);
		
		QSplitter *pSplitter = new QSplitter(this);
		
		m_pTreeView = new QTreeView(pSplitter);
		m_pTreeView->setModel(pDirSystemModel);
		m_pTreeView->setCurrentIndex(pDirSystemModel->index(strRootPath));
		connect(m_pTreeView, &QTreeView::expanded, this, &Widget::changeListViewRootPath);
		connect(m_pTreeView, &QTreeView::clicked, this, &Widget::changeListViewRootPath);
		connect(m_pTreeView, &QTreeView::doubleClicked, this, &Widget::changeListViewRootPath);
		
		m_pListView = new QListView(pSplitter);
		m_pListView->setModel(pFileSystemModel);
		m_pListView->setRootIndex(pFileSystemModel->index(strRootPath));
		connect(m_pListView, &QListView::doubleClicked, [this]{
			if (pFileSystemModel->isDir(index)){
				QString strDir = pFileSystemModel->filePath(index);
				m_pTreeView->setCurrentIndex(pDirSystemModel->index(strDir));
				m_pListView->setRootIndex(index);
			}
		});
		
		QHBoxLayout *layout = new QHBoxLayout(this);
		layout->setWidget(pSplitter);
		setLayout(layout);
	}
	
	void Widget::changeListViewRootPath(const QModelIndex &index)
	{
		QString strDir = pDirSystemModel->filePath(index);
		m_pListView->setRootIndex(pFileSystemModel->index(strDir));
	}
雒珣 2019-12-23
  • 打赏
  • 举报
回复
引用 3 楼 待续_1006 的回复:
右边还是建议listview合理一些吧,到显示数据的时候用其他控件
listview能多列显示吗?比如我想显示文件的详细信息
待续_1006 2019-12-20
  • 打赏
  • 举报
回复
右边还是建议listview合理一些吧,到显示数据的时候用其他控件
雒珣 2019-12-19
  • 打赏
  • 举报
回复
在百度上也没有搜到这种情况怎么处理,或者说QtableView有没有这样的功能呢
  • 打赏
  • 举报
回复
QXXView按道理来说就是一个View。显示的数据可以交由别的代理来处理吧。而且点击QTreeView的时候已经知道了文件路径了,根据路径再读一次显示出来应该也可以吧

16,799

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧