Results 1 to 4 of 4

Thread: QWidget promotion with child widgets

  1. #1
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QWidget promotion with child widgets

    I would like to create a simple file retrieval widget that has within it a QLineEditand a QPushButton within a QHBoxLayout. When a user clicks on the QPushButton, it opens a QFileDialog to find a file whose path gets placed into the QLineEdit.

    Normally, I would just sub-class QWidget as MyFileLineEdit and give it the QLineEdit and QPushButton as children, but functionally it's basically a QLineEdit with extra features and I would like it to interface like one (particularly with Qt Designer via promotion).

    Is there a way to do this without manually connecting all of QLineEdit's signals and slots in MyFileLineEdit? I have tried to inherit directly from QLineEdit, but I can't figure out how to insert the QPushButton next to it.

  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: QWidget promotion with child widgets

    Yes. Subclass QLineEdit, use QWidget::setContentMargins() to "push" the right edge of the widget towards left to make room for the button, then create an instance of QToolButton (it's much better than push button here), make it a child of QLineEdit and position it in the space available.

    Or just use QwwFileChooser or QwwButtonLineEdit.
    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:

    Phlucious (21st February 2012)

  4. #3
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget promotion with child widgets

    That's exactly what I was looking for! Interestingly, those two wwWidgets you linked are pretty much the immediate applications that I had in mind.

    What are the advantages of using a QToolButton instead of a QPushButton outside of the context of a QToolBar? I don't think I fully understand the QAction system yet.

  5. #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: QWidget promotion with child widgets

    QToolButton can take less space and can be associated with a QAction easier than QPushButton.
    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.


Similar Threads

  1. promotion problems with designer
    By szisziszilvi in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2011, 08:27
  2. Replies: 1
    Last Post: 16th September 2010, 15:57
  3. Child widgets
    By poporacer in forum Newbie
    Replies: 6
    Last Post: 12th August 2010, 03:04
  4. Replies: 5
    Last Post: 18th April 2010, 23:31
  5. Child Widgets In MainWindow
    By RY in forum Newbie
    Replies: 3
    Last Post: 4th October 2008, 08:39

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.