Results 1 to 6 of 6

Thread: Custom widget, dealing with resize the right way?

  1. #1
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Custom widget, dealing with resize the right way?

    Hello,
    I'm designing a new custom widget (very simple, just a groupbox with some stuff in it, but since I need many copies I've decided to create a widget).

    What is the right way to deal with resizing?

    Right now when I resize the widget, the groupbox inside it stays the same size, which of course is not what I want. I've tried to reimplement resizeEvent to grab the event and resize the groupbox. It works, but then I can squeeze the groupbox down to size 0, which messes everything up when putting the widget inside a Layout (it gets squeezed to size 0 by the spacers).

    Is there a full example of creating a custom widget and implementing it in designer?
    I've looked at the "world time clock" one on the Qt site, but it's very very minimal.... for example nowhere it cites the Q_PROPERTY and Q_ENUM macros. I found out they still work in Qt4 just by cut'n'paste from the old Qt3 widget.

  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: Custom widget, dealing with resize the right way?

    You need a layout for all widgets containing other widgets, starting from the top-most one. If your widget is derived from QWidget, you need to apply a layout on it as well (and on the groupbox). If it is derived directly from the groupbox, you need to apply a layout on the groupbox (and possibly on other widgets acting as containers).

  3. #3
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Custom widget, dealing with resize the right way?

    Thanks for your answer. It seems to be working fine....
    Just to make sure I'm doing things right. My widget is derived from QWidget.

    In the constructor:
    - I create a GroupBox.
    - I create a GridLayout for the GroupBox and populate it with stuff.
    - I do GroupBox->setLayout(GridLayout).
    - I create a HBoxLayout and addWidget(GroupBox) to it.
    - I do a this->setLayout(HBoxLayout).

    For the 2nd part of my question: I've searched for Q_PROPERTY and it only appears in the Qt 3.3 documentation, but it seems to work fine in Qt4. Is it supposed to exist and be documented somewhere?

  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: Custom widget, dealing with resize the right way?

    Why don't you derive from QGroupBox? You'd have one level of hierarchy less...

    Q_PROPERTY is documented. Open Assistant and type in Q_PROPERTY into the index tab.

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

    Ishark (26th May 2008)

  6. #5
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Custom widget, dealing with resize the right way?

    Right, I'll derive directly from GroupBox.
    I've never used assistant and I've installed it. It does indeed document Q_PROPERTY.... is the documentation found there identical to the website?

    I'm also having a very weird behaviour with my widget. If I use a GroupBox to group my buttons/labels and redefine mousePressEvent to trap mouse events (not the one on buttons of course) then I never get a single event. If I replace the GroupBox with a Frame then I get the events. Is there some fundamental difference between the two? They used to work the same way in Qt3.

    I'll try to derive directly from GroupBox to see if it changes anything.

    EDIT: it does, when deriving from GroupBox I get the events as expected.
    Last edited by Ishark; 23rd May 2008 at 15:53.

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Custom widget, dealing with resize the right way?

    Quote Originally Posted by Ishark View Post
    I've never used assistant and I've installed it.
    It's shipped together with Qt.

    It does indeed document Q_PROPERTY.... is the documentation found there identical to the website?
    Yes.
    J-P Nurmi

Similar Threads

  1. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 11:52
  2. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 15:06
  3. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 16:38
  4. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 14:12
  5. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 08:00

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.