Results 1 to 7 of 7

Thread: Resizing back the widget

  1. #1
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs down Resizing back the widget

    I have written following piece of code using PyQt.

    Qt Code:
    1. class QChoices(QWidget):
    2.  
    3. def __init__(self):
    4. QWidget.__init__(self)
    5. self.setLayout(QVBoxLayout())
    6. policy = QSizePolicy()
    7. policy.setVerticalPolicy(QSizePolicy.Minimum)
    8. self.setSizePolicy(policy)
    9.  
    10. def addChoice(self, choice):
    11. checkBox = QCheckBox(choice)
    12. checkBox.setCheckState(Qt.Checked)
    13. self.connect(checkBox, SIGNAL('stateChanged(int)'), self.remove)
    14. self.layout().addWidget(checkBox)
    15.  
    16. def remove(self, state):
    17. if state != Qt.Unchecked:
    18. raise Exception('Choice checked back again!')
    19. self.sender().hide()
    20. self.sender().deleteLater()
    21. self.updateGeometry()
    To copy to clipboard, switch view to plain text mode 

    It is supposed to work like attachments in GMail, where you can uncheck a check box to remove an attachment and it disappears. So it works ok, but the problem is, that the widget doesn't resize itself to be smaller again, when one of the checkboxes is hidden. I have set vertical size policy in this widget and in parent widget to Minimum, but it doesn't help. I just can't figure out, how to make it resize itself properly. Could anyone help me with this?

  2. #2
    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: Resizing back the widget

    Take a look at QLayout::sizeConstraint.

  3. #3
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Resizing back the widget

    I tried:

    Qt Code:
    1. self.layout().setSizeConstraint(QLayout.SetMinimumSize)
    To copy to clipboard, switch view to plain text mode 

    but it didn't work.

    The only thing that works, is to explicitly resize the widget to the minimalSize, but it doesn't still works, when this widget is inside some other one.

    I implemented sizHint and minimalSizeHint, I try to call updateGeometry, but nothing helps. I really don't get this sizing stuff and would really appreciate help on this one.

  4. #4
    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: Resizing back the widget

    Mimumum means it can be bigger than what is returned by sizeHint (it means that sizeHint is the MINIMUM size that can be set). I think you want "Fixed".

  5. The following user says thank you to wysota for this useful post:

    gruszczy (22nd November 2008)

  6. #5
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Resizing back the widget

    It works. Nearly perfectly, thanks a lot. It canot be resized now manually (which is a slight imperfection ;-)) - on the other hand I don't really now, how it should behave after manual resize. I don't need it anyway, so I'll just stick to this one.

    My another problem is, that I don't really get, how all this resizing works. Could you suggest me some reading? I tried this: http://doc.trolltech.com/4.1/layout.html, but there is not information about this sizeConstraint. I'd really like to dig a bit more into it, especially that I have similar problems with other widgets (but the other way - I want them get bigger, when some internal widget is built).

  7. #6
    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: Resizing back the widget


  8. The following user says thank you to wysota for this useful post:

    gruszczy (23rd November 2008)

  9. #7
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Resizing back the widget

    Thanks, I'll take a look.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52
  3. Open FileDialog showing Back of the Widget in Mac
    By shyam prasad in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2007, 06:33
  4. Resizing child Widget
    By Pragya in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2007, 06:58
  5. Widget resizing problem
    By fwohlfert in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2006, 08:16

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.