QComboBox和QSpinBox在QTableWidget与适当的对齐方式 [英] QComboBox and QSpinBox in QTableWidget with appropriate alignment

查看:784
本文介绍了QComboBox和QSpinBox在QTableWidget与适当的对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个QTable窗口小部件有2列,在第一列有一个QComboBox和在第二列有一个QSpinBox,以便组合框获取表的所有空间,只有一个很小的地方离开

首先,使用 setCellWidget() 设置 QComboBox QSpinBox 作为在相应单元格中显示的窗口小部件。



,请使用 horizo​​ntalHeader()访问 QTableView ,然后设置 QheaderView qt-project.org/doc/qt-4.8/qheaderview.html#ResizeMode-enumrel =nofollow noreferrer> ResizeMode

  QTableWidget * table = new QTableWidget(this); 
table-> setColumnCount(2);
table-> setRowCount(1);
table-> setCellWidget(0,0,new QComboBox(table));
table-> setCellWidget(0,1,new QSpinBox(table));
table-> horizo​​ntalHeader() - > setResizeMode(0,QHeaderView :: Stretch);
table-> horizo​​ntalHeader() - > setResizeMode(1,QHeaderView :: ResizeToContents);


How to create a QTable widget which has 2 columnes, and in first column there is a QComboBox and in the second column there is a QSpinBox so that the combo box gets all the space of table and only a very small place leaves for QSpinBox (for 2-3 digits).

解决方案

First, use setCellWidget() to set the QComboBox and QSpinBox as the widgets to be displayed in the appropriate cell.

Second, use horizontalHeader() to access the QHeaderView for the QTableView, then set the ResizeMode accordingly.

QTableWidget* table = new QTableWidget( this );
table->setColumnCount( 2 );
table->setRowCount( 1 );
table->setCellWidget ( 0, 0, new QComboBox( table ) );
table->setCellWidget ( 0, 1, new QSpinBox( table ) );
table->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
table->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );

这篇关于QComboBox和QSpinBox在QTableWidget与适当的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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