PDA

View Full Version : QTableView and stylesheet horizontal scrolling problem



aphexgt
18th October 2012, 23:00
I'm having a problem on OSX with QTableView and scrolling horizontally. The problem happens when I set a stylesheet for QTableView. Any cells I've configured using QTableView->setIndexWidget will move out of their cells when scrolling horizontally. I can't reproduce this problem on Windows. Here is some code:



main_window::main_window(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui = new Ui::MainWindow();
ui->setupUi(this);

_model = new TableModel;
ui->myTable->setModel(_model);
int size = _model->rowCount();

for (int i = 0; i < size; i++)
{
QModelIndex index = _model->index(i, SIXTH_COLUMN);
ui->myTable->setIndexWidget(index, new QComboBox);
}

QString ss = "QTableView { background-color: rgb(237,237,241); border: none; border-radius: 4px; padding: 4px 4px; color: rgb(46,66,59);}";
setStyleSheet(ss);
}


In the above, TableModel is a subclass of QAbstractTableModel with eight columns. If I remove the last two lines (setting the stylesheet), the cell will not move when scrolling horizontally. Is this a bug or am I doing something wrong? I've attached my sources files.

I'm using Qt 4.8.3 with Mountain Lion 10.8.2 & XCode 4.5.