Results 1 to 5 of 5

Thread: How to set focus (select) a tabbed QDockWidget?

  1. #1

    Default How to set focus (select) a tabbed QDockWidget?

    Hi,

    I'm adding two QDockWidget controls in this way:

    QDockWidget *templateDock = ....
    addDockWidget(Qt::LeftDockWidgetArea, templateDock);

    QDockWidget *propertyDock = ...

    tabifyDockWidget(templateDock, propertyDock);
    templateDock->raise();


    I want the first dock (template Dock to have a focus - be active), but tabifyDockWidget() makes the second widget active.
    raise() method does not work.

    Please help.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set focus (select) a tabbed QDockWidget?

    Maybe setFocus() ?

  3. #3

    Default Re: How to set focus (select) a tabbed QDockWidget?

    No, this did not help.

  4. #4
    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 set focus (select) a tabbed QDockWidget?

    You don't tell us which platform you are using. QWidget::raise() works just fine here on Linux. It's possible that it won't work on your platform before the widget is shown, i.e. after the constructor is finished. Try this:

    Qt Code:
    1. MainWindow(QWidget *p = 0): QMainWindow(p) {
    2. ...
    3.  
    4. templateDock = new QDockWidget(tr("Template"), this);
    5. templateDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    6. templateDock->setWidget(new QTextEdit(templateDock));
    7. addDockWidget(Qt::LeftDockWidgetArea, templateDock);
    8.  
    9. propertyDock = new QDockWidget(tr("Property"), this);
    10. propertyDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    11. propertyDock->setWidget(new QTextEdit(propertyDock));
    12. addDockWidget(Qt::LeftDockWidgetArea, propertyDock);
    13.  
    14. tabifyDockWidget(templateDock, propertyDock);
    15. // templateDock->raise(); // <<<< works here on Linux
    16.  
    17. QTimer::singleShot(0, this, SLOT(tweakUi())); // <<<< Try deferring it
    18. }
    19.  
    20. public slots:
    21. void tweakUi() {
    22. templateDock->raise();
    23. }
    To copy to clipboard, switch view to plain text mode 

  5. #5

    Default Re: How to set focus (select) a tabbed QDockWidget?

    Chris,

    thank you for the hint - delayed raise() did work. I also found the code which prevented the raise() to work in first place:

    connect(this, SIGNAL(updateContent(NodeCore &, bool)), propertyView, SLOT(onUpdateContent(NodeCore &, bool)));
    tabifyDockWidget(m_templateDock, m_propertyDock);
    m_templateDock->raise();

    Apparently onUpdateContent() slot belonging to propertyView which is displayed inside of propertyDock was called after this code (which was executed in constructor) and caused propertyDock to become active. I still don't understand the reason why - I commented out the whole onUpdateContent() slot and it was still interfering with raise() by activating propertyDock (presumably from templateDock). Only if I comment out the whole connect() line of code, the problem disappears.

    The code is running under Windows XP.

Similar Threads

  1. Replies: 6
    Last Post: 27th August 2012, 23:44
  2. Catching events for tabBar of tabbed QDockWidget
    By koosh in forum Qt Programming
    Replies: 2
    Last Post: 16th June 2009, 23:17
  3. How can I know if a QDockWidget is tabbed?
    By ricardo in forum Qt Programming
    Replies: 1
    Last Post: 8th May 2009, 06:51
  4. Tabbed QDockWidget question
    By Khal Drogo in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2008, 17:57
  5. QDockWidget Tabbed State
    By jtaylor108 in forum Newbie
    Replies: 2
    Last Post: 2nd August 2007, 00:16

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.