单元格pyqt中的小部件对齐方式 [英] Widget alignment in cell pyqt

查看:67
本文介绍了单元格pyqt中的小部件对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 PyQT4 和 Python 2.7 中开发一些工具,但遇到了一个小问题.我有 3 个按钮存储在小部件中,该小部件位于表格 (QTableWidget) 的单元格中.所以我的问题是我无法将小部件与单元格顶部对齐,并且工具不会将行高调整为小部件最小/固定高度中定义的大小.

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.

这是使用方法 resizeRowToContents 现在的样子.

Here is how it looks now with method resizeRowToContents.

我想要这样的东西

我用固定行高做了类似的事情,但不是我想要的方式.

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

推荐答案

我以非常简单的方式解决了这个问题.首先,我将布局的边距更改为 0px(后来我将其更改为 3px 以进行填充),这使我的对齐完全对齐到左上角.下一步是为每一行设置最小大小,我通过以下行进行:

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)

在构造函数中添加.

之后我收到了我想要的东西:

After that I received exactly what I want:

  1. 顶部和底部有一些填充的小部件
  2. 行的大小不固定,因此项目中也允许多行文本

这篇关于单元格pyqt中的小部件对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆