susu1213的个人主页

http://www.qtcn.org/bbs/u/207864  [收藏] [复制]

susu1213

  • 0

    关注

  • 0

    粉丝

  • 0

    访客

  • 等级:新手上路
  • 总积分:0
  • 保密,2011-01-01

最后登录:2021-04-07

更多资料

日志

QTableWidget单元格插入QLabel问题

2021-04-07 17:34
大家好,我最近使用QT遇到一些问题请大家帮我看看。
我在QTableWidget的单元格中插入一个QLabel控件后立马获取QLabel的rect(),发现获取到的值很小。但是在另一个线程里获取到的rect()是正确的,我想问问这是为什么?
widget.cpp代码如下:
void Widget::initWidget(){    label = new QLabel(ui->tableWidget);    ui->tableWidget->setCellWidget(0, 0, label);
    rect = label->rect();    std::cout << "rect l:" << rect.left()              << " t:" << rect.top()              << " r:" << rect.right()              << " b:" << rect.bottom()              << std::endl;}
void Widget::fun(){    QLabel *p = (QLabel *)ui->tableWidget->cellWidget(0,0);    if (p == NULL) {        std::cout << "lable == NULL" << std::endl;        return;    }    QRect rect = p->rect();    std::cout << "fun rect l:" << rect.left()              << " t:" << rect.top()              << " r:" << rect.right()              << " b:" << rect.bottom()              << std::endl;}main.cpp代码如下:int main(int argc, char *argv[]){    QApplication a(argc, argv);    Widget w;    w.initWidget();    w.show();
    std::thread id = std::thread( [&](){        QRect rect = w.label->rect();
        std::cout << "thread rect l:" << rect.left()                  << " t:" << rect.top()                  << " r:" << rect.right()                  << " b:" << rect.bottom()                  << std::endl;
        w.fun();    });

    int ret = a.exec();
    if (id.joinable())        id.join();
    return ret;}
分类:默认分类|回复:0|浏览:26|全站可见|转载
 

下一篇:

上一篇:

Powered by phpwind v8.7 Certificate Copyright Time now is:04-13 17:55
©2005-2016 QTCN开发网 版权所有 Gzip disabled