问题
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:
- widget with some pading from top and bottom
- not fixed size of rows so multiline text in item is allowed as well
来源:https://stackoverflow.com/questions/15461143/widget-alignment-in-cell-pyqt