QLabel sizehint is too small
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a QAbstractItemDelegate and in the paint method, I am trying to paint the text from a label. But the problem I am seeing is that the size hint of the QLabel is always too small for the text it contains. How can I fix this? For example: QLabel *testlabel = new QLabel(); testlabel->setText("This is some test text that doesnt fit:"); testlabel->adjustSize(); QRect rect(testlabel->geometry()); Qt::Alignment alignFlags = testlabel->alignment(); painter->setFont(testlabel->font()); painter->drawRect(rect); painter->drawText(rect, alignFlags