默认情况下,内容超出边界后会自动省略,以...代替,而且无法出现水平滚动条。
方法有两种:
方法一:
m_leftTreeWidget->header()->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_leftTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents);
m_leftTreeWidget->header()->setStretchLastSection(false);
m_leftTreeWidget->setAutoScroll(true);
方法二:
connect(m_leftTreeWidget, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onLeftDevTreeClicked(const QModelIndex &)));
connect(m_leftTreeWidget, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(onLeftDevTreeClicked(const QModelIndex &)));
connect(m_leftTreeWidget, SIGNAL(expanded(const QModelIndex&)), this, SLOT(onLeftDevTreeClicked(const QModelIndex &)));
响应函数:
void CLocalDirTreeWgt::onLeftDevTreeClicked(const QModelIndex &index)
{
m_leftTreeWidget->resizeColumnToContents(0);
}