Results 1 to 3 of 3

Thread: Access widgets

  1. #1
    Join Date
    Nov 2006
    Posts
    16
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Post Access widgets

    Hi,
    Please let me know how to access widgets in other dialogs?

    Thanks in advance

  2. #2
    Join Date
    Aug 2006
    Location
    Zürich, Switzerland
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access widgets

    Easiest is to provide a pointer to the widget(s) in the dialog constructor and, for example, save the pointer in a member variable of your class which is derived from QDialog. This way all methods of your dialog class can access the widget(s).

    Header file

    Qt Code:
    1. class MyDialog : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public: // Operations
    6.  
    7. // ctor
    8. MyDialog(QWidget* parent, QWidget* myOtherWidget);
    9.  
    10.  
    11. private: // Attributes
    12.  
    13. QWidget* m_otherWidget;
    14.  
    15. ....
    To copy to clipboard, switch view to plain text mode 

    Implementation file

    Qt Code:
    1. MyDialog::MyDialog(QWidget* parent, QWidget* myOtherWidget)
    2. : QDialog(parent),
    3. m_otherWidget(myOtherWidget)
    4. {
    5. ...
    6.  
    7. m_otherWidget->callWhateverMethodIsAccessibleFromThatWidget();
    8.  
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 

    Ernst

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access widgets

    Windows are just normal classes, so you can do it just like if you were accessing data stored in some other class.

    Remember that usually you don't want to access other window's widgets directly, since it's an implementation detail that should be hidden from other classes.

    Also read this: http://www.qtcentre.org/forum/f-newb...gobj-4444.html and search the forum before you ask a question.

Similar Threads

  1. QLogText & QLogTable : 2 widgets to display text log
    By fcoiffie in forum Qt-based Software
    Replies: 7
    Last Post: 28th April 2019, 07:52
  2. How to paint across/over multiple widgets?
    By richy in forum Qt Programming
    Replies: 3
    Last Post: 31st August 2006, 10:57
  3. Replies: 11
    Last Post: 7th July 2006, 13:09
  4. How to movable dock widgets?
    By becond in forum Qt Tools
    Replies: 3
    Last Post: 21st February 2006, 19:57
  5. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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.