Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem: QTableWidget with stylesheet don't scroll items
Forum Update on Monday, May 27th 2025

Problem: QTableWidget with stylesheet don't scroll items

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nnatarr
    wrote on 28 Feb 2012, 14:45 last edited by
    #1

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

    }@

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on 28 Feb 2012, 14:57 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nnatarr
        wrote on 28 Feb 2012, 15:01 last edited by
        #3

        [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.

        1 Reply Last reply
        0

        1/3

        28 Feb 2012, 14:45

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved