Results 1 to 9 of 9

Thread: Dialog design and maintaining square widgets.

  1. #1
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Dialog design and maintaining square widgets.

    For the past two three days i am battling to get "perfect" settings dialog layout. Once it seems ok while other time i feel i should do something.
    I now have two approaches to my dialog(attached) and i admit it isn't that good.

    filldialog.ui was my first attempt (which i feel clumsy with lots of group boxes)
    filldialog1.ui was approach taken from http://www.kdedevelopers.org/node/2475

    I have two questions
    • Which of the above is better ?
    • How can i keep my preview widget always square ?
    • Any suggestions to improve any of the dialogs ?


    Thanks
    Attached Files Attached Files
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  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: Dialog design and maintaining square widgets.

    How about something like this?
    Attached Files Attached Files

  3. #3
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Dialog design and maintaining square widgets.

    The idea is fine but sometimes from "usability" point of view using an alternative to tabbed dialog seems to fit better.
    Ofcourse i am not a usability expert

    BTW is it possible to make the preview widget to allow size change while keeping it square ?
    I think i should look for heightForWidth but i couldn't find this in designer. Also i implemented this method in the preview widget to return the width but it doesn't work as expected.
    Any help ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  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: Dialog design and maintaining square widgets.

    Quote Originally Posted by Gopala Krishna View Post
    BTW is it possible to make the preview widget to allow size change while keeping it square ?
    Yes, sure. heightForWidth is the way to go, but you have to write some code - you won't be able to do that only from Designer.
    Also i implemented this method in the preview widget to return the width but it doesn't work as expected.
    This is not enough. You have to inform the layout it should actually ask for heightForWidth. As far as I remember you can do that by setting an appropriate size policy. Although this article is meantfor Qt3, it should be fine for Qt4 too: http://doc.trolltech.com/qq/qq04-height-for-width.html

  5. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Dialog design and maintaining square widgets.

    Thanks, the sizepolicy hint fixed it. But i have one more problem.
    I can now resize the dialog to even zero size I have actually set minimum size to both the preview widget as well as the group box housing it, but for some strange reason setting the sizepolicy's setHeightForWidth(true) breaks the size constraints.

    This is my heightForWidth implementation.

    Qt Code:
    1. PreviewWidget::heightForWidth(int w) const
    2. {
    3. return w;
    4. }
    To copy to clipboard, switch view to plain text mode 

    and i set sizepolicy in constructor as
    Qt Code:
    1. PreviewWidget::PreviewWidget(int paintingType, QWidget *parent) :
    2. QWidget(parent),
    3. m_lightPixmap(10, 10),
    4. m_darkPixmap(10, 10),
    5. m_headStyle(1),
    6. m_headWidth(20),
    7. m_headHeight(40),
    8. m_startAngle(0),
    9. m_spanAngle(180),
    10. m_drawBackground(true),
    11. m_paintingType(paintingType)
    12. {
    13. m_lightPixmap.fill(Qt::white);
    14. m_darkPixmap.fill(Qt::lightGray);
    15. setMinimumSize(QSize(140, 140));
    16. resize(140, 140);
    17. if(m_paintingType == Painting::ArrowType) {
    18. calcHeadPoints();
    19. }
    20.  
    21. QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    22. policy.setHeightForWidth(true);
    23. setSizePolicy(policy);
    24. }
    To copy to clipboard, switch view to plain text mode 
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  6. #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: Dialog design and maintaining square widgets.

    Reimplement minimumSizeHint().

  7. #7
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Dialog design and maintaining square widgets.

    Thanks for the hint - just read the docs again and now the concepts are ok to me :-)
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  8. #8
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dialog design and maintaining square widgets.

    Alas, I appear to be too uneducated to follow Wysota (always complete and lucid) instructions. I'm trying to make a custom widget that is always square, but it refuses to work for me.

    I'm using PyQt4

    In Designer, I make a window with two objects side by side, one of which is a QWidget that I promote to my custom SquareWidget class. The window is given a horizontal layout containing the two objects.

    Qt Code:
    1. #!/usr/bin/env python
    2. from PyQt4 import QtGui, QtCore
    3.  
    4. class SquareWidget(QtGui.QWidget):
    5.  
    6. def __init__(self, parent=None):
    7. QtGui.QWidget.__init__(self, parent)
    8.  
    9. theSizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
    10. theSizePolicy.setHeightForWidth(True)
    11. self.setSizePolicy(theSizePolicy)
    12.  
    13. def paintEvent(self, event):
    14. painter = QtGui.QPainter()
    15. painter.begin(self)
    16. painter.setBrush(QtGui.QBrush(QtGui.QColor( 255, 255, 255)))
    17. rectangle = QtCore.QRectF(0.0, 0.0, self.width(), self.height())
    18. painter.drawRect(rectangle)
    19. painter.end()
    20.  
    21. def heightForWidth(self, width):
    22. return width
    23.  
    24. def sizeHint(self):
    25. w = self.width()
    26. return QtCore.QSize( w, self.heightForWidth(w) )
    To copy to clipboard, switch view to plain text mode 

    Unfortunately, when run, the widget does draw as a white rectangle, but when the window is re-sized, the widget does NOT stay square.

    I'm sure I'm making a fairly elementary mistake, but I cannot see what I'm doing wrong. Is there anything obvious?

  9. #9
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Thanks
    3
    Thanked 12 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Dialog design and maintaining square widgets.

    In the layout that contains the widget, make sure the widget is added with stretch factor set to 1 or more. Else the layout will "force" it to use less space.

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.