You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, February 20th 2009, 6:32pm

QScrollBar never visible in my QWidget

Hello,
I have QWidget with a QTableWidget and 2 QScrollBars, one horizontal and one vertical.
I cannot use the scrollbars of the QTableWidget because the scrollbars reach up to the table headers, which I don't want.
When this widget is visible (see code below) I cannot see the scrollbars, they never appear. Do you know why?
Thank you.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
DynamicTable::DynamicTable(int rows, int columns, QWidget * parent)
: QWidget(parent)
{
QScrollBar vScrollBar(Qt::Vertical);
QScrollBar hScrollBar(Qt::Horizontal);
vScrollBar.setMinimum(0);
vScrollBar.setSingleStep(1);
vScrollBar.setMaximum(50);
vScrollBar.setValue(10);
vScrollBar.setPageStep(10);
hScrollBar.setMinimum(0);
hScrollBar.setSingleStep(1);
hScrollBar.setMaximum(50);
hScrollBar.setValue(10);
hScrollBar.setPageStep(10);
hScrollBar.setMinimumSize(QSize(50,50));
QSizePolicy sp(QSizePolicy::Minimum,QSizePolicy::Minimum);
hScrollBar.setSizePolicy(sp);

QHBoxLayout * horizontalLayout = new QHBoxLayout();
QVBoxLayout * verticalLayout = new QVBoxLayout();
QTableWidget table;
table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table.setRowCount(rows);
table.setColumnCount(columns);

horizontalLayout->addWidget(&vScrollBar);
horizontalLayout->addWidget(&table);
vScrollBar.setVisible(true);

verticalLayout->addLayout(horizontalLayout);
verticalLayout->addWidget(&hScrollBar);
hScrollBar.setVisible(true);

setLayout(verticalLayout); fillTable(); // some function which adds stuff in the QTableWidget
}

2

Friday, February 20th 2009, 6:44pm

Source code

1
2
3
4
5
6
DynamicTable::DynamicTable(int rows, int columns, QWidget * parent)
: QWidget(parent)
{
QScrollBar vScrollBar(Qt::Vertical);
QScrollBar hScrollBar(Qt::Horizontal);
// after this function exit these objects will be autodestroyed.
Fighting fire with fire.
Three can keep a secret if two of them are dead.

3

Monday, February 23rd 2009, 1:07pm

QScrollBar never visible in my QWidget

You are right! I suppose I was asleep while writing this code... :sleeping:
Thank you for this reply.