Results 1 to 3 of 3

Thread: setContentsMargins in QAbstractItemView

  1. #1
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question 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:

    Qt Code:
    1. QTextEdit* textEdit1 = new QTextEdit;
    2. QTextEdit* textEdit2 = new QTextEdit;
    3.  
    4. MyOwnView* myView = new MyOwnView(this);
    5. myView->setContentsMargins(50,50,50,50);
    6. QGridLayout* gridLayout1 = new QGridLayout(myView);
    7. gridLayout1->addWidget(textEdit1, 0, 0);
    8. myView->setLayout(gridLayout1);
    9.  
    10. QFrame* frame = new QFrame(this);
    11. frame->setContentsMargins(50,50,50,50);
    12. QGridLayout* gridLayout2 = new QGridLayout(frame);
    13. gridLayout2->addWidget(textEdit2, 0, 0);
    14. frame->setLayout(gridLayout2);
    15.  
    16. QStackedWidget* stackedWidget = new QStackedWidget(this);
    17. stackedWidget->addWidget(myView);
    18. stackedWidget->addWidget(frame);
    19.  
    20. setCentralWidget(stackedWidget);
    To copy to clipboard, switch view to plain text mode 

    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?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

  3. #3
    Join Date
    Jan 2006
    Location
    Minsk, Brest, Belarus
    Posts
    54
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face 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.

Similar Threads

  1. Replies: 2
    Last Post: 26th February 2009, 10:12
  2. Need help getting QAbstractItemView syntax correct
    By Hookem in forum Qt Programming
    Replies: 3
    Last Post: 4th December 2008, 09:34
  3. Subclassing QAbstractItemView
    By psih128 in forum Qt Programming
    Replies: 4
    Last Post: 13th October 2008, 07:32
  4. QAbstractItemView and updating selected items
    By Isaac in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 12:23
  5. QAbstractItemView
    By defumar in forum Newbie
    Replies: 9
    Last Post: 22nd January 2008, 13:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.