In the following code there are two stylesheets: problemStylesheet and okStylesheet. Everything works fine when I’m using okStylesheet for QTableWidget. Labels are scrolling. Problem is that labels are not scrolling if I use problemStylesheet. What can cause this problem? I've tried to find the solution, but couldn't find any information that might be helpful.
Qt 4.8.0, Mac OS X Lion.
Example code:
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *baseWidget = new QWidget;
QTableWidget *tableWidget = new QTableWidget(baseWidget);
tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tableWidget->setColumnCount(1);
tableWidget->horizontalHeader()->setVisible(false);
tableWidget->verticalHeader()->setVisible(false);
tableWidget->horizontalHeader()->setStretchLastSection(true);
tableWidget->verticalHeader()->setDefaultSectionSize(52);
tableWidget->setShowGrid(false);
tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
QString problemStylesheet = "QTableWidget { background-color: green; } QTableWidget::item { border: 1px solid #000; }";
QString okStylesheet = "QTableWidget { } QTableWidget::item { border: 1px solid #000; }";
tableWidget->setStyleSheet(problemStylesheet);
tableWidget->setRowCount(20);
for (int i = 0; i < 20; ++i) {
QLabel *label = new QLabel(QString("").setNum(i), tableWidget);
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
tableWidget->setCellWidget(i, 0, label);
}
QVBoxLayout *verticalLayout = new QVBoxLayout();
verticalLayout->setMargin(0);
verticalLayout->setSpacing(0);
verticalLayout->setContentsMargins(0, 0, 0, 0);
baseWidget->setLayout(verticalLayout);
verticalLayout->addWidget(tableWidget);
baseWidget->show();
return app.exec();
}
UPDATE: It seems like everything is ok on Linux and Windows. So the problem appears only on Mac OS.