Results 1 to 6 of 6

Thread: a tight QFrame is all i need

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default a tight QFrame is all i need

    I was tryin to create my widget as follows

    Qt Code:
    1. MyWidget::MyWidget(QString description, double value,
    2. QString unit,QWidget* parent)
    3. :QFrame(parent)
    4. {
    5. //ctor
    6. QHBoxLayout* lo = new QHBoxLayout (this);
    7. setLayout(lo);
    8. setContentsMargins(1,1,1,1);
    9.  
    10. QLabel* lblDescription = new QLabel (description,this);
    11. lo->addWidget(lblDescription);
    12.  
    13. QDoubleSpinBox* sbValue = new QDoubleSpinBox(this);
    14. sbValue->setMaximum(MaxValue);
    15. sbValue->setValue(value);
    16. lo->addWidget(sbValue);
    17.  
    18. QLabel* lblUnit = new QLabel (unit,this);
    19. lo->addWidget(lblUnit);
    20. }
    To copy to clipboard, switch view to plain text mode 

    I want my frame to be just enough for line edit,and two labels (since they are laid out horizontally) no more no less, This will save me some screen space. I will be re using this widget a lot in one page (widget) and they will be laid out vertically.

    Now, my question is that, is there any easyway to do the tight fitting of my frame to just the three widgets?. right now there is a gap between the 2 of my MyWidget laid out Vertically.

    baray98

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: a tight QFrame is all i need

    Try QWidget::setContentsMargins(int,int,int,int) and QLayout::setSpacing(int).

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

    Default Re: a tight QFrame is all i need

    setContentsMargins() is not the way to go. Try QLayout::setMargin() and QLayout::setSpacing() instead. Contents margins are 0 by default, so setting them to 1 will only make an empty border around your widget.

  4. #4
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: a tight QFrame is all i need

    void QLayout::setContentsMargins ( int left, int top, int right, int bottom ) works for me

    thanks guys you rock!!!
    baray98

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

    Default Re: a tight QFrame is all i need

    Really? Can you post a screenshot?

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: a tight QFrame is all i need

    I guess a negative content margin cuts the margin set by the layout. Of course, as Wysota already mentioned, the proper way would be to just remove the margin set by the layout.
    J-P Nurmi

Similar Threads

  1. Using a QFrame as a color selection indicator
    By KShots in forum Qt Tools
    Replies: 8
    Last Post: 14th June 2011, 23:55
  2. how to determine geometry of a QFrame
    By impeteperry in forum Qt Programming
    Replies: 3
    Last Post: 10th October 2007, 19:07
  3. QFrame inserting text
    By Pharell in forum Qt Programming
    Replies: 9
    Last Post: 8th October 2007, 09:55
  4. QFrame showing 4 different widgets
    By hgedek in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 17:29
  5. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.