2 Attachment(s)
setContentsMargins in QAbstractItemView
Hi everybody,
I would like to make a view of my own, containing some widgets layouted in a QGridLayout. So I sub classed QAbstractItemView. But I have a problem with the function setContentsMargins() : this function does nothing. What is strange is that with a QFrame (parent of QAbstractItemView), it is possible to set the margins. Here is my code:
Code:
MyOwnView* myView = new MyOwnView(this);
myView->setContentsMargins(50,50,50,50);
gridLayout1->addWidget(textEdit1, 0, 0);
myView->setLayout(gridLayout1);
frame->setContentsMargins(50,50,50,50);
gridLayout2->addWidget(textEdit2, 0, 0);
frame->setLayout(gridLayout2);
stackedWidget->addWidget(myView);
stackedWidget->addWidget(frame);
setCentralWidget(stackedWidget);
On the first attached image the QTextEdit is inside a QFrame and the second one it is inside a QAbstractItemView
Did somebody experiment the same issue? Is it a Qt bug or one of my own?
Re: setContentsMargins in QAbstractItemView
I think you should first set the layout for the widget and then change the margins and not the other way round.
Re: setContentsMargins in QAbstractItemView
QGridLayout has two functions that you shoulf use:
setMargin( int ) // you should use 0
setSpacing( int ) // 0
This is the solution of your problem.:D