I’d like to display 2. Style using QHeaderView.ResizeToContents option.
Is this a pyqt bug?
I very much doubt it's a PyQt bug. What you're seeing is more likely to be caused by the fact that when you call setSpan, the automatic layout features of Qt tables works in unexpected ways. In my experience (see left side of image below) as soon as you use setSpan, expect to have to manually set individual cell sizes. And that can get complicated pretty quickly. It's unfortunate, but I'm not aware of any other way to solve the problem. However, it goes without saying that others might have different ways of confronting the problem, so it's worth seeking feedback from them too.