0

I had a problem with QTableView widget: I need to horizontal scroll whole widget with headers, but standart scrolling scroll only content, but not headers.

Then I tried to add QScrollArea like this (this all in QDockWidget):

class matrix : public QScrollArea {
};

in constructor:

QVBoxLayout* layout = new QVBoxLayout(this);

tableView = new QTableView(this);
tableView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
layout->addWidget(tableView);

this->setLayout(layout);

but it doesn't work properly: scrolling bar doesn't appear.

(sorry, if I break some rules - it's my first question here, and sorry for my bad english)

railmisaka
  • 971
  • 6
  • 14
  • What happens, if you attach the layout to the viewport, assuming there is one set? Like `QVBoxLayout* layout = new QVBoxLayout(viewport());` – tomvodi Feb 18 '15 at 13:42
  • I'm a newbie in Qt and may be I don't understand you properly, but i tried this - no difference. – railmisaka Feb 18 '15 at 13:47
  • I've posted it as an answer, because it includes too much code for a comment. – tomvodi Feb 18 '15 at 14:09

1 Answers1

0

You could for instance remove the layout and set the QTableView directly as viewport.

tableView = new QTableView;
setWidget(tableView);
setWidgetResizable(true);
tableView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tomvodi
  • 5,577
  • 2
  • 27
  • 38