开发者

QComboBox and QSpinBox in QTableWidget with appropriate alignment

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 com开发者_StackOverflow社区bo 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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜