0
点赞
收藏
分享

微信扫一扫

Qt中qtablewidget用cellwidget添加控件,使控件在单元格居中显示

忍禁 2022-03-12 阅读 63

我们在给qtablewidget当中添加按钮的时候一般采用cellwidget的方式,在widget中添加布局,并在布局中添加控件:

 def buttonForRow(self):
        widget = QWidget()

        # 文件重选
        re_choose_button = QPushButton("重选文件")
        re_choose_button.clicked.connect(self.re_choose_buttonClicked)
        re_choose_button.setFixedHeight(32)
        # 上移
        up_button = QPushButton("↑↑")
        up_button.clicked.connect(self.up_buttonClicked)
        up_button.setFixedHeight(32)
        # 下移
        down_button = QPushButton("↓↓")
        down_button.clicked.connect(self.down_buttonClicked)
        down_button.setFixedHeight(32)

        # 按钮布局
        hlayout = QHBoxLayout()
        hlayout.addWidget(re_choose_button)
        hlayout.addWidget(up_button)
        hlayout.addWidget(down_button)
        hlayout.setContentsMargins(5, 2, 5, 2)  #  控件居中
        widget.setLayout(hlayout)
        return widget

效果图

举报

相关推荐

0 条评论