2 Attachment(s)
Re: Custom widget won't size properly in a table cell
Hello.
I'm trying to use a custom widget as an editor in a QTableView's cell, but for some very obscure reason (to me), the custom widget won't size properly. However, when I replace my custom widget with a simple QPushButton, the component is now sized as it should, filling the whole cell. See the attachments.
Here's the important code:
This is how I create my custom widget
Code:
{
horizontalLayout->setSpacing(0);
horizontalLayout->setObjectName("horizontalLayout");
m_pathLineEdit->setObjectName("pathLineEdit");
browseToolButton->setObjectName("browseToolButton");
browseToolButton->setText("...");
horizontalLayout->addWidget(m_pathLineEdit);
horizontalLayout->addWidget(browseToolButton);
this->setLayout(horizontalLayout);
}
And here's the delegate code:
Code:
{
}
{
// return CBrowseWidget(parent); THIS DOES NOT WORK!!
return new QPushButton("test", parent
);
// THIS WORKS!! }
{
editor->setGeometry(option.rect);
}
Any ideas?
Added after 12 minutes:
Answering to myself: horizontalLayout->setContentsMargins(0, 0, 0, 0); did the trick... :rolleyes:
Re: Custom widget won't size properly in a table cell
try setting the margins:
setContentsMargins()