Problem: QTableWidget with stylesheet don't scroll items



  • 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?

    Qt 4.8.0, Mac OS X Lion.

    @#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();
    

    }@



  • Way to go, hardcore procedural programming in an OOP language and an OOP framework. I really hope this is not your usual programming practice, just some quick code for illustrative purposes.



  • [quote author="ddriver" date="1330441073"]Way to go, hardcore procedural programming in an OOP language and an OOP framework. I really hope this is not your usual programming practice, just some quick code for illustrative purposes.[/quote]

    This code is just for example of problem, of course.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.