Results 1 to 7 of 7

Thread: Multiple tabbed QDockWidget and default selection

  1. #1
    Join Date
    Jul 2009
    Location
    France
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Multiple tabbed QDockWidget and default selection

    Hi,

    I created several QDockWidget which are tabbified by default using this :
    Qt Code:
    1. mainWindow_->tabifyDockWidget(prevDock, dock);
    To copy to clipboard, switch view to plain text mode 

    When the aplication starts, this is the last tab which is selected by default. I want to have the FIRST tab selected instead.
    Using
    Qt Code:
    1. setFocus()
    To copy to clipboard, switch view to plain text mode 
    on first tab/dock does not change anything.

    Any idea ?

    BR

  2. #2
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiple tabbed QDockWidget and default selection

    After a LOT of searching I finally came up with a work around that mostly works. It's cumbersome. I basically, get all of the tabBars in my main window and check their children until I find the QTabBar that contains my dock widgets. (I couldn't get to the QDockWidgets by grabbing the tab bar so I check the tabText to see if the tab label is what I expect.) Then, I call setCurrentIndex on that tabBar to select the desired tabe thus putting my QDockWidget on top.

    The other issue I ran into is that I couldn't do this while still in my project open slot (the tabbar had not finished updating.) To get around this I set a timer. When the timer fires I'm able to go through the process I explain above, and the desired tab is on top.

    I do hope that an api method is added to handle this more simply.

  3. The following user says thank you to winkle99 for this useful post:

    oberlus (12th November 2011)

  4. #3
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Multiple tabbed QDockWidget and default selection

    firstTab->show();
    firstTab->raise();

  5. #4
    Join Date
    Apr 2011
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multiple tabbed QDockWidget and default selection

    thanks srazi.. your solution is great....

  6. #5

    Default Re: Multiple tabbed QDockWidget and default selection

    It does not work for me.
    firstTab->raise() has no effect. Any ideas?

  7. #6
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple tabbed QDockWidget and default selection

    I'm also having an issue with this. I would appreciate any advice on being able to set the current tabbed dockwidget.

  8. #7
    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: Multiple tabbed QDockWidget and default selection

    Call QWidget::raise() on the dock widget you want on top. There's not much more to it than that.
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. class MainWindow: public QMainWindow {
    5. Q_OBJECT
    6. public:
    7. MainWindow(QWidget *p = 0): QMainWindow(p) {
    8. setCentralWidget(new QTextEdit(this));
    9.  
    10. dock1 = new QDockWidget("Dock1", this);
    11. dock1->setWidget(new QLabel("Dock 1 content", this));
    12. addDockWidget(Qt::RightDockWidgetArea, dock1);
    13. dock2 = new QDockWidget("Dock2", this);
    14. dock2->setWidget(new QLabel("Dock 2 content", this));
    15. addDockWidget(Qt::RightDockWidgetArea, dock2);
    16. tabifyDockWidget(dock1, dock2);
    17.  
    18. flop = true;
    19. connect(&timer, SIGNAL(timeout()), SLOT(flip()));
    20. timer.start(2000);
    21. }
    22. public slots:
    23. void flip() {
    24. if (flop)
    25. dock1->raise();
    26. else
    27. dock2->raise();
    28. flop = !flop;
    29. }
    30.  
    31. private:
    32. QDockWidget *dock1;
    33. QDockWidget *dock2;
    34. QTimer timer;
    35. bool flop;
    36. };
    37.  
    38. int main(int argc, char *argv[])
    39. {
    40. QApplication app(argc, argv);
    41.  
    42. MainWindow m;
    43. m.show();
    44. return app.exec();
    45. }
    46. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. Default size of a QListWidget inside a QDockWidget
    By rakuco in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2007, 08:01
  2. different arrangement of QDockWidget than default
    By Wurgl in forum Qt Programming
    Replies: 3
    Last Post: 13th July 2006, 10:41

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.