Results 1 to 7 of 7

Thread: How to subclass a control in *.ui?

  1. #1
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to subclass a control in *.ui?

    For I use layout to arrange the control's position.But i have to inherit some control,for example, qtable,to realize some function.How Can I reach this? Thanks!!

  2. #2
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to subclass a control in *.ui?

    Well, I'm not sure this is what you mean, but...
    If you have a class that is derived from a widget available in designer like "class myCustomTableView : public QTableView" then you can right click the widget in designer and choose promote to custom widget. You must specify the proper header file for your custom widget.

  3. #3
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to subclass a control in *.ui?

    Quote Originally Posted by jrideout
    Well, I'm not sure this is what you mean, but...
    If you have a class that is derived from a widget available in designer like "class myCustomTableView : public QTableView" then you can right click the widget in designer and choose promote to custom widget. You must specify the proper header file for your custom widget.
    What I mean is that ,for example,if there is a QTable in *.ui, and I have a class named
    QMyTable derived from QTable,How can i relate these two?In Mfc,I can use CWnd::SubclassDlgItem to do this. this is the detailed description in MSDN.

    And I do my best to understand and test what you descripted,but I have no idea at last:
    Quote Originally Posted by jrideout
    right click the widget in designer and choose promote to custom widget.
    ,there is no such option in right click options.


    CWnd::SubclassDlgItem
    This method dynamically subclasses a control created from a dialog box template, and attach it to this CWnd object. When a control is dynamically subclassed, windows messages will route through the CWnd message map and call message handlers in the CWnd class first. Messages that are passed to the base class will be passed to the default message handler in the control.

    This method attaches the Windows control to a CWnd object and replaces the WndProc and AfxWndProc functions of the control. The function stores the old WndProc in the location returned by the CWnd::GetSuperWndProcAddr method.

    BOOL SubclassDlgItem(
    UINT nID,
    CWnd* pParent );
    Parameters
    nID
    Specifies the control ID.
    pParent
    Specifies the control parent, this is usually a dialog box.
    Return Value
    Nonzero if the function is successful; otherwise, it is zero.

    Example
    class CMyButton : public CButton {...};
    // m_myButton is a CMyButton object member of CAboutDlg

    BOOL CAboutDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();
    // IDC_BUTTON1 is the ID for a button on the
    // dialog template used for CAboutDlg.
    m_myButton.SubclassDlgItem(IDC_BUTTON1, this);

    return TRUE; // Return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
    }
    Last edited by coralbird; 5th April 2006 at 02:15.

  4. #4
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to subclass a control in *.ui?

    Sorry my solution is for Qt4, I just noticed you are using Qt3.

    Anyway for folks that read this thread and are using 4 here is a clarification.

    In designer, with your form open, right click the widget in the form.

    The context menu from right clicking should look like this:
    Qt Code:
    1. Change objectName
    2. Change toolTip
    3. Change whatsThis
    4. ------------------
    5. Promote to Custom Widget
    6. ------------------
    7. Cut
    8. Copy
    9. ...
    To copy to clipboard, switch view to plain text mode 

    Select "Promote to Custom Widget". A dialog will appear where you can put in the name of the derived class and a header that defines it.

    You can edit the ui manually to achive the same effect. Try something like this:
    Qt Code:
    1. <ui version="4.0" >
    2. <class>Dialog</class>
    3. <widget class="QDialog" name="Dialog" >
    4. <property name="windowTitle" >
    5. <string>Dialog</string>
    6. </property>
    7. <widget class="QTableView" name="tableView" >
    8. </widget>
    9. <widget class="myCustomTable" name="customTableView" >
    10. </widget>
    11. </widget>
    12. <customwidgets>
    13. <customwidget>
    14. <class>myCustomTable</class>
    15. <extends>QTableView</extends>
    16. <header>mycustomtable.h</header>
    17. <container>0</container>
    18. <pixmap></pixmap>
    19. </customwidget>
    20. </customwidgets>
    21. </ui>
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to subclass a control in *.ui?

    For qt3 try tools->custom->Edit Custom Widget in designer

  6. The following user says thank you to jrideout for this useful post:

    coralbird (5th April 2006)

  7. #6
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to subclass a control in *.ui?

    First special thanks to jrideout!

    Quote Originally Posted by jrideout
    For qt3 try tools->custom->Edit Custom Widget in designer
    I have find the entrance,and I will test tomorrow. Thanks again.

  8. #7
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to subclass a control in *.ui?

    Quote Originally Posted by jrideout
    For qt3 try tools->custom->Edit Custom Widget in designer
    Sure,Through this function,I have reached my target.It's really a usful function.
    thanks jrideout again.

Similar Threads

  1. Replies: 6
    Last Post: 3rd February 2006, 09:48

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.