开发者

Qt: how to get the size of QTableView?

I have a QTableView, that the Model is bound to. I fill the model (using model->setItem) and then would like to adjust the widths of the columns on the table. I would like to use the relative size, so the first column should be 60% of the whole width, the second one - 40%.

int tableWidthEffective = ui->table开发者_运维知识库Packages->width();
ui->tablePackages->setColumnWidth(0, tableWidthEffective * 0.6);

The problem is when I open the dialog the first time the width of the table is much less than really, it works only in the second time. The table is in Layout. As soon as I delete layout everything works properly but I need to use the layout. How to get the proper size of the table still using layout?

Thanks


In Qt, widgets resize themselves by emitting signals to their parents and children. This needs a message loop. So try this from your dialog box code, before you show it for the first time:

setAttribute (Qt::WA_DontShowOnScreen, true) ; // Prevent screen flicker
show() ;

QEventLoop EventLoop (this) ;
for ( ; ; )
  if (!EventLoop.processEvents()) break ;

hide() ;
setAttribute (Qt::WA_DontShowOnScreen, false) ;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜