[Qt-interest] remove QSplitter children / disable splitter dragging.
Brad Howes
howes at ll.mit.edu
Thu Oct 22 23:12:21 CEST 2009
On Oct 22, 2009, at 3:48 AM, Thomi Richards wrote:
> I'm trying to build a UI that contains a QSplitter with two child
> widgets (one on each side). Under normal operations, the user can
> interact with this QSplitter as you would expect. However, I want a
> toggle button that hides / removes one of the two children of the
> splitter, and only shows the one remaining widget.
>
> Right now I'm simply calling "childWidget->hide()" when this mode is
> enabled. However, the splitter can still be moved, which looks very
> odd, since one side of the splitter is showing nothing.
Here's what I did, though it may be overkill for Qt4. I have a class
called Splittable that is derived from QStackedWidget (!). In the
Splittable interface, there is a split() slot that will split a view
in two -- I support infinite levels of splitting, each new view can
subsequently be split in two. The split() method takes a
Qt::Orientation value, the new QWidget object to show in the split
view. There is also a slot called unsplitWith() with takes the object
to keep after the unsplit.
So, why QStackedWidget? Because in some old Qt (3?) release, I had
widget (re)parenting issues. Using QStackedWidget saved me from this
by allowing me to have two views for a QWidget object: one in which it
owns the whole area, and another in which it is one part of a
QSplitter view. When unsplit, I simply invoke
QStackedWidget::removeWidget() with the QSplitter object I am
removing, and voila! I have the original QWidget view immediately
available.
I can send you the Splitter class code if you want. It is very small.
Brad
--
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420
More information about the Qt-interest-old
mailing list