scrollbar on QTableView does not scroll
我做了只有一列的表格,每行内容比较长,我希望能自动滚动,但是按照别的表格,一样一样的方法,只不过那个表格有很多列很多行.然后死活不显示全部.
list_tableview_->horizontalHeader()->setStretchLastSection(true);
list_tableview_->setAutoScroll(true);
要不 就显示省略号,要不就是显示前半部分,把滚动条设置老显示,发现根本滚动不了.长长的一段数字,只显示前半部分,很困扰
list_tableview_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
查了很多资料,都是说 resizeColumnToContents 就可以,事实上我另外一个表格就是这样的,到这个地方就行不通了,
然后看到这个问题:
http://python.6.x6.nabble.com/QTableView-not-showing-vertical-scroll-bar-td4996966.html
其中,David 回复.
it looks like there's a bug in Qt that only occurs if there is only one row
in the table. If you change the return value of rowCount() to 2 then you get
the desired behaviour. Perhaps it would be worth looking in the bug tracker
at bugreports.qt-project.org for a similar bug report, or file a new one.
他说只有一行的时候qt有个bug,会导致这样.我的列数只有1,然后我就把我的列数改为2,果然好了
author: wsh
email: tongzhuodenilove@163.com