QTableWidget的实际屏幕尺寸

时间:2019-11-22 09:00:48

标签: c++ qt

我在我的应用程序中使用QTableWidget。计算最大要显示的列,我需要获取QTableWidget的实际宽度。我尝试了不同的方法:

此(QTableWidget)

this->geometry()->width() = Will always report 640.
this->horizontalHeader()->length() = Will always report 1660 here in case of the amount of columns.

但是QTableWidget的大小恰好为1000像素。这使我感到困惑。

我的第一个主意是,好吧,您在错误的位置询问应用程序的大小。 所以我也问过MDIChild建成之后。

    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的大小,而不读取其内容,仅读取其框架吗?

0 个答案:

没有答案
相关问题