2 Attachment(s)
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 :)
1 Attachment(s)
Re: Dialog design and maintaining square widgets.
How about something like this?
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 ?
Re: Dialog design and maintaining square widgets.
Quote:
Originally Posted by
Gopala Krishna
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.
Quote:
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
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 :confused: 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.
Code:
PreviewWidget::heightForWidth(int w) const
{
return w;
}
and i set sizepolicy in constructor as
Code:
PreviewWidget
::PreviewWidget(int paintingType,
QWidget *parent
) : m_lightPixmap(10, 10),
m_darkPixmap(10, 10),
m_headStyle(1),
m_headWidth(20),
m_headHeight(40),
m_startAngle(0),
m_spanAngle(180),
m_drawBackground(true),
m_paintingType(paintingType)
{
m_lightPixmap.fill(Qt::white);
m_darkPixmap.fill(Qt::lightGray);
setMinimumSize
(QSize(140,
140));
resize(140, 140);
if(m_paintingType == Painting::ArrowType) {
calcHeadPoints();
}
policy.setHeightForWidth(true);
setSizePolicy(policy);
}
Re: Dialog design and maintaining square widgets.
Reimplement minimumSizeHint().
Re: Dialog design and maintaining square widgets.
Thanks for the hint - just read the docs again and now the concepts are ok to me :-)
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.
Code:
#!/usr/bin/env python
from PyQt4 import QtGui, QtCore
def __init__(self, parent=None):
QtGui.
QWidget.__init__
(self, parent
)
theSizePolicy.setHeightForWidth(True)
self.setSizePolicy(theSizePolicy)
def paintEvent(self, event):
painter.begin(self)
painter.
setBrush(QtGui.
QBrush(QtGui.
QColor( 255,
255,
255))) rectangle
= QtCore.
QRectF(0.0,
0.0, self.
width(), self.
height()) painter.drawRect(rectangle)
painter.end()
def heightForWidth(self, width):
return width
def sizeHint(self):
w = self.width()
return QtCore.
QSize( w, self.
heightForWidth(w
) )
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?
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.