Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Focusing on a tabified QDockWidget in PyQt

Tags:

qt

pyqt

pyqt4

I have three QDockWidgets which are tabbed at startup using QMainWindow.tabifyDockWidget.

In the main window, after all of the addDockWidget calls:

self.tabifyDockWidget(self.dock_widget1, self.dock_widget2)
self.tabifyDockWidget(self.dock_widget1, self.dock_widget3)

Based on certain actions, I'd like to select one of these tabs and bring it to focus, or, on top of the other two, if it's not already visible. I've tried using setVisible and setWindowState(Qt.WindowActive), but nothing changes.

Is there a way to programmatically select a tabbed dock widget and bring it to the front?

like image 257
brianz Avatar asked Aug 17 '09 22:08

brianz


3 Answers

Thanks to an answer on the qt-interest mailing list, this is very simple to do with QWidget.raise():

http://qt-project.org/doc/qt-4.8/qwidget.html#raise

In PyQt, it's QWidget.raise_():

http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#raise

like image 122
brianz Avatar answered Nov 02 '22 22:11

brianz


For me:

dock2.show();

dock2.raise();

was enough. But yes, both are needed!

like image 9
Jimmytaker Avatar answered Nov 02 '22 21:11

Jimmytaker


I haven't tested this, but here's what I would try in Qt 4.5+ (I'll leave the PyQt conversion to you):

class MyMainWindow ; // A QMainWindow

void MyMainWindow::bringToFront( QDockWidget* dockIn )
{
   QList<QDockWidget*> docks = tabifiedDockWidgets( dockIn ) ;
   foreach( QDockWidget* dock, docks )
   {
      // Move second dock on top of first dock widget.
      tabifyDockWidget( dock, dockIn ) ;
   }
}

See QMainWindow::tabifiedDockWidgets() and QMainWindow::tabifyDockWidget().

like image 2
swongu Avatar answered Nov 02 '22 20:11

swongu