Qt-interest Archive, June 2007
Qt Designer for a Periodic Table
Message 1 in thread
Hello to all intelligent life out there!
I'm one of the developers of Avogadro, a Qt-based 3D chemical editor.
Right now, I'm in the process of implementing a widget dialog with
buttons for the periodic table. Basically, these would be a like a
toolbar, so I did a layout in Qt Designer for each QToolButton as an
element. Pretty easy really.
Then I realized that QGroupBox is just a visual grouping and I really
wanted QButtonGroup.
So here's my problem:
* There's a very clear visual layout for all these buttons, so I'd
like to keep the designer layout.
* There's a clear logical layout -- I'd like to be able to group them
to get the button ids (which would be the element number).
Any suggestions?
Thanks,
-Geoff
--
[ signature omitted ]
Message 2 in thread
Hi Geoff,
I'm very interested in the responses you get; I'll chime in if I feel I
can add anything.
I'm also in the process of re-implementing a periodic table dialog (my
old one was done with bare-bones Win32).
Cheers,
Mark
(arguslab modeling program: www.arguslab.com)
Geoffrey Hutchison wrote:
> Hello to all intelligent life out there!
>
> I'm one of the developers of Avogadro, a Qt-based 3D chemical editor.
> Right now, I'm in the process of implementing a widget dialog with
> buttons for the periodic table. Basically, these would be a like a
> toolbar, so I did a layout in Qt Designer for each QToolButton as an
> element. Pretty easy really.
>
> Then I realized that QGroupBox is just a visual grouping and I really
> wanted QButtonGroup.
>
> So here's my problem:
> * There's a very clear visual layout for all these buttons, so I'd
> like to keep the designer layout.
> * There's a clear logical layout -- I'd like to be able to group them
> to get the button ids (which would be the element number).
>
> Any suggestions?
>
> Thanks,
> -Geoff
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
--
[ signature omitted ]
Message 3 in thread
> * There's a very clear visual layout for all these buttons, so I'd
> like to keep the designer layout.
> * There's a clear logical layout -- I'd like to be able to group them
> to get the button ids (which would be the element number).
Remembering the periodic table, I'd suggest to add the buttons manually.
Looking at
http://www.periodensystem.info/periodensystem.htm
it even seems not to be usefule to use spacers.
Maybe you should use a QTableView with buttons inside?
--
[ signature omitted ]
Message 4 in thread
On May 31, 2007, at 9:46 PM, Geoffrey Hutchison wrote:
> Then I realized that QGroupBox is just a visual grouping and I
> really wanted QButtonGroup.
OK, here's what I worked out. I'm posting because there seem to be
many questions on using QButtonGroup with Designer. So I'll post for
the sake of Google archives. :-)
Mark, I'll contact you off-list about code-sharing for this
particular example of a periodic table. :-)
The trick is that you do the layout in Qt Designer as you want it to
appear visually. This may include a few QGroupBox objects for visual
grouping. Then in the "glue" code for your widget (e.g., in the
constructor) you create a few private QButtonGroups. I used code like
this (i.e., using QObject::findChildren) since all my QToolButton
objects are elements and their order reflects the element type.
> ui.setupUi(this);
>
> elementGroup = new QButtonGroup(this);
> unsigned int element = 1;
> foreach(QToolButton *child, findChildren<QToolButton*>()) {
> elementGroup->addButton(child, element++);
> child->setCheckable(true);
> }
>
> connect(elementGroup, SIGNAL(buttonClicked(int)),
> this, SLOT(buttonClicked(int)));
Of course if you have multiple button groups, you might just grab the
appropriate members of the ui object and add them.
So once again for posterity: use designer for the visual layout. If
you need logical layout with QButtonGroup, add those in your code. It
would be nice to add these directly through Designer, but it's not
bad this way either.
Cheers,
-Geoff
--
[ signature omitted ]
Message 5 in thread
Geoffrey Hutchison wrote:
> Hello to all intelligent life out there!
>
> I'm one of the developers of Avogadro, a Qt-based 3D chemical editor.
> Right now, I'm in the process of implementing a widget dialog with
> buttons for the periodic table. Basically, these would be a like a
> toolbar, so I did a layout in Qt Designer for each QToolButton as an
> element. Pretty easy really.
>
> Then I realized that QGroupBox is just a visual grouping and I really
> wanted QButtonGroup.
>
> So here's my problem:
> * There's a very clear visual layout for all these buttons, so I'd
> like to keep the designer layout.
> * There's a clear logical layout -- I'd like to be able to group them
> to get the button ids (which would be the element number).
>
> Any suggestions?
>
I might be missing the elephant in the room, but how about this:
1) In designer layout the buttons in a huge grid layout with lots of
empty spaces. If fact you can layout just the left column and bottom row
to get all the empty spaces to show up.
2) In the code rip through all the child widgets of the parent that
contains the buttons and add them to a QButtonGroup. Then attach a slot
to the buttonReleased( QAbstractButton* ) signals.
3) You will have to inspect the button itself to determine which element
it is. You can't use a group with ids since you don't know the actual
ordering of the children.
You could probably use a subclass of QToolButton (or even just
QAbstractButton) to tag it with an element number and you probably want
to do custom painting anyway to draw more than just the symbol. This
could be a made a plugin for designer. You could enforce that all the
buttons are checkable via this subclass too.
Good Luck,
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard