C++ QTableWidget实际屏幕大小
我在应用程序中使用QTableWidget。要计算要显示的最大列数,我需要获得QTableWidget的实际宽度。我尝试了不同的方法: 这个(QTableWidget) 但是QTableWidget的大小正好是1000像素。这让我困惑 我的第一个想法是,好吧,你在错误的位置询问应用程序的尺寸。 因此,我还询问了MDI子项构建之后的情况C++ QTableWidget实际屏幕大小,c++,qt,C++,Qt,我在应用程序中使用QTableWidget。要计算要显示的最大列数,我需要获得QTableWidget的实际宽度。我尝试了不同的方法: 这个(QTableWidget) 但是QTableWidget的大小正好是1000像素。这让我困惑 我的第一个想法是,好吧,你在错误的位置询问应用程序的尺寸。 因此,我还询问了MDI子项构建之后的情况 QVBoxLayout * dlgSplitter = new QVBoxLayout(this); QHBoxLayout * topNav =
QVBoxLayout * dlgSplitter = new QVBoxLayout(this);
QHBoxLayout * topNav = new QHBoxLayout(this);
QWidget * wdgSplitter = new QWidget(this);
QLabel *labelTopNav = new QLabel(this);
labelTopNav->setText(tr("This is a header"));
topNav->addWidget(labelTopNav);
topNav->setContentsMargins(1,8,1,0);
dlgSplitter->setContentsMargins(0,0,0,0);
dlgSplitter->setSpacing(0);
dlgSplitter->setMargin(0);
dlgSplitter->addLayout(topNav);
scanBoard = new QScanBoard(200, 83); //This ist he "this->" control from above
//scrollArea->setWidget(scanBoard);
dlgSplitter->addWidget(scanBoard);
wdgSplitter->setLayout(dlgSplitter);
this->setCentralWidget(wdgSplitter);
int nWidth = scanBoard->geometry().width();
qDebug("Breite: %d ",nWidth);
但这也会抛出与类本身相同的数据
有没有人知道一种方法可以读取QTableWidget的大小,而不需要它的内容,只需要它的框架?在您的代码示例中,这是什么??对不起,QTableWidget640听起来像是在实际大小计算完成之前报告的默认宽度。有一次,我为菜单编写了一个示例,并意识到在调用
show()
之前,我没有获得正确的小部件几何图形。(FY:-相关部分是<代码> StaskButto::MousPrimeSeViver(/Cult>))以处理实际大小,可以考虑从<代码> QTable WIDGET < /代码>中派生类,并重写<代码> ResiZEVER()/<代码>。我记得我们曾经意识到resizeEvent()
的一个问题:新的大小可以从widget(调用width()
)或从传递给resizeEvent()
的QResizeEvent*
中获得。其中只有一个是正确的。不幸的是,我忘了是哪一个。只是为了记住这一点……我脑海中突然出现了另一个东西:QTableWidget
是从它派生出来的。后者是一个组合小部件-它包含视口
以及水平和垂直滚动条。viewport()
提供实际的客户端区域。因此,viewport()->width()
可能提供比width()
更好的值。(描述中提到了视口。)
QVBoxLayout * dlgSplitter = new QVBoxLayout(this);
QHBoxLayout * topNav = new QHBoxLayout(this);
QWidget * wdgSplitter = new QWidget(this);
QLabel *labelTopNav = new QLabel(this);
labelTopNav->setText(tr("This is a header"));
topNav->addWidget(labelTopNav);
topNav->setContentsMargins(1,8,1,0);
dlgSplitter->setContentsMargins(0,0,0,0);
dlgSplitter->setSpacing(0);
dlgSplitter->setMargin(0);
dlgSplitter->addLayout(topNav);
scanBoard = new QScanBoard(200, 83); //This ist he "this->" control from above
//scrollArea->setWidget(scanBoard);
dlgSplitter->addWidget(scanBoard);
wdgSplitter->setLayout(dlgSplitter);
this->setCentralWidget(wdgSplitter);
int nWidth = scanBoard->geometry().width();
qDebug("Breite: %d ",nWidth);