QTreeView 水平滚动条
时间: 2024-01-15 12:52:45 浏览: 132
Qt美化之基础控件美化.pdf
5星 · 资源好评率100%
QTreeView 的水平滚动条是根据需要显示的,默认情况下采用的是Qt::ScrollBarAsNeeded的设置。也就是说,如果在QTreeView中添加了项目,并且项目的文本超出了视图的可见范围,那么水平滚动条会自动显示,以便用户可以滚动查看所有内容。 但是,有时候可能会出现水平滚动条未显示的情况,导致部分文本不可见。为了解决这个问题,可以使用QTreeView自带的槽函数,并将其与树形控件的pressed信号或expanded信号绑定。绑定后,在槽函数中调用resizeColumnToContents()函数,即可自动显示水平滚动条并调整列的宽度,以确保所有文本都可见。具体的代码示例如下:
treeView = new QTreeView();
connect(treeView, SIGNAL(pressed(QModelIndex)), this, SLOT(slot_treeView_pressed(QModelIndex)));
connect(treeView, SIGNAL(expanded(QModelIndex)), this, SLOT(slot_treeView_pressed(QModelIndex)));
void QWidget::slot_treeView_pressed(QModelIndex modeIndex) {
treeView->resizeColumnToContents(modeIndex.column());
}<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [QTreeView和scrollbar窗口自适应](https://blog.csdn.net/groundhappy/article/details/53375531)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [QTreeView树形控件自动显示水平滚动条(resizeColumnToContents())](https://blog.csdn.net/naibozhuan3744/article/details/91981663)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文