Results 1 to 3 of 3

Thread: Expanding custom widget

  1. #1
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Expanding custom widget

    Hello,

    I will have a QVBoxLayout that will house a series of labels and custom button widgets.

    I'm implementing a custom button widget based on QAbstractButton that takes a QList of QStrings and displays one of them as the default text and then has a downward facing arrow next to the string if list contains other strings. When the user clicks on the button, I want to show a drop-down (but flat) box underneath the button I already have with the other strings from the list.

    I'm overriding the sizeHint() to return a fixed size for the button based on the font and overriding paintEvent() to do all the custom drawing. Since sizeHint() is returning the size of the button, in paintEvent() the rect() that I can used to draw is 200x48 which is fine. However, I want to dynamically expand the entire widget vertically to add the necessary number of additional button choices underneath.

    I've looked at using rect().adjust/adjusted to expand the rect() and qDebug() shows that the rect() has grown as needed, but I also want the layout to expand to handle the newly expanded button widget so that the options are visible. And when a new selection is made or another button is selected, I will shrink the widget back to it's original size and I want the layout to shrink back down.

    I know that I can create a QVboxLayout and add a QGroupBox with a bunch of widgets and when I call the show() and hide() functions, the layout expands and shrink as needed.

    So my question is, what do I have to trigger/return/emit from my custom widget to allow the layout to expand to show my newly expanded widget?

    I've attached a couple of screenshots from our UI design to show that I'm talking about. The image with Bottom/Top shows the buttons on the right in their collapsed form. The image with Pressure shows the button in its expanded form with the Radiation entry being pushed down to accommodate the larger button. Once the user selects one of the options, the button would collapse and the Radiation line would now end up right underneath Pressure just like Bottom/Top..

    Regards
    Attached Images Attached Images
    Last edited by Raz0rEdge; 13th November 2012 at 16:14.

  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: Expanding custom widget

    Are you calling updateGeometry() when the logical size of the widget changes?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Raz0rEdge (14th November 2012)

  4. #3
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Expanding custom widget

    Quote Originally Posted by wysota View Post
    Are you calling updateGeometry() when the logical size of the widget changes?
    I found this after some more digging and it is indeed what I needed along with setting setSizeConstraint(QLayout::SetFixedSize) on the QVboxLayout I was using to hold my widget. This made the QVboxLayout listen to the sizeHint() of my widget and the updateGeometry() call, as you mentioned, puts it all together.

    So I now have my widget resizing and QVboxLayout adjusting to it.

    Regards

Similar Threads

  1. Replies: 0
    Last Post: 19th March 2012, 19:09
  2. Replies: 1
    Last Post: 23rd June 2011, 23:09
  3. Expanding/shrinking a widget
    By punkypogo in forum Qt Programming
    Replies: 6
    Last Post: 27th May 2008, 16:50
  4. Expanding and hiding a widget
    By Dauntless in forum Newbie
    Replies: 3
    Last Post: 12th December 2006, 06:28
  5. Replies: 1
    Last Post: 5th November 2006, 23:50

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.