Widget alignment in cell pyqt

若如初见. 提交于 2019-12-07 14:55:35

问题


I'm developing some tool in PyQT4 and Python 2.7 and I stuck in a little problem. I've 3 buttons in stored in widget and that widget is in cell in the table (QTableWidget). So my problem is that I can't align widget to top of cell and tool doesn't resize row height to defined in widget minimum/fixed height.

Here is how it looks now with method resizeRowToContents.

And I want something like this

I did something similar with fixed row height but its not the way I want.


回答1:


I solved this problem in quite simply way. First of all I changed margin of layout to 0px (later I changed that to 3px to have padding) and this made my alignment exactly to top, left corner. Next step was set minimum size for each row and that I made by following line:

self.verticalHeader().setMinimumSectionSize(30)

added in constructor.

After that I received exactly what I want:

  1. widget with some pading from top and bottom
  2. not fixed size of rows so multiline text in item is allowed as well


来源:https://stackoverflow.com/questions/15461143/widget-alignment-in-cell-pyqt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!