3

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.

teapot_of_wine
  • 516
  • 3
  • 18
  • Running this on Linux (Ubuntu 11.10) there is no observable difference in behavior between using the two style sheets. Other than the fact that one is green and one is not, it looks like it is working fine. What do you mean by "labels are scrolling"? – Chris Feb 28 '12 at 17:05
  • @Chris: I made a screenshot (http://dl.dropbox.com/u/8720074/Screen%20Shot%202012-02-28%20at%2023.48.28.png). As you can see, vertical scrollbar is at the bottom, but we see labels 0, 1, 2, 3, not the labels 16, 17, 18, 19. – teapot_of_wine Feb 28 '12 at 17:53
  • 2
    Just submitted an issue to QT: https://bugreports.qt-project.org/browse/QTBUG-25180 – CsTamas Apr 05 '12 at 09:00

1 Answers1

0

In my experience I often got debug messages from NSScrollWheel when I ran my apps on MAC's.

I would suggest avoiding scroll views when using qt on MAC's

ajtrichards
  • 29,723
  • 13
  • 94
  • 101