Results 1 to 2 of 2

Thread: how to get the type of the QMdiSubWindow

  1. #1
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default how to get the type of the QMdiSubWindow

    i have severl different type of widget using in QMdiArea,i want to update the menus and the action status as the widgets changes,i used the
    Qt Code:
    1. QMdiSubWindow * QMdiArea::activeSubWindow () const
    To copy to clipboard, switch view to plain text mode 
    the get the current active QMdiSubWindow.but i want to know which widget it is ?
    how?
    thank you in andvance

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to get the type of the QMdiSubWindow

    The return from QMdiArea::activeSubWindow() is always a pointer to a QMdiSubWindow. What you are trying to determine is the class of the widget contained inside the QMdiSubWindow. You can do that with qobject_cast:
    Qt Code:
    1. QMdiSubWindow *sw = mdiArea->activeSubWindow();
    2. if (sw) {
    3. if (FooWidget *foo = qobject_cast<FooWidget*>(sw->widget())) {
    4. // do something FooWidget specific
    5. }
    6. else if (BarWidget *bar = qobject_cast<BarWidget*>(sw->widget())) {
    7. // do something BarWidget specific
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    You probably want to do this work in a slot attached to the subWindowActivated() signal.

    If you have widgets of the same class but with different purposes then you could use the QObject::name() to differentiate them.

    You could just keep a track of the QMdiSubwindow pointers you got when you created the the sub windows and compare those to the active one.

Similar Threads

  1. Frameless QMdiSubWindow
    By meadmaker in forum Newbie
    Replies: 4
    Last Post: 14th September 2010, 12:28
  2. QMdiSubWindow stays always on top
    By SiS-Shadowman in forum Qt Programming
    Replies: 0
    Last Post: 20th July 2010, 18:55
  3. QMdiSubWindow keyPressEvent
    By M. in forum Newbie
    Replies: 0
    Last Post: 5th December 2009, 00:05
  4. How to get the position of a QMdiSubWindow
    By doberkofler in forum Qt Programming
    Replies: 2
    Last Post: 6th November 2009, 19:35
  5. Close a QMdiSubwindow
    By John_P in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2008, 18:23

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.