Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxTabbedWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxTabbedWidget.h"
13 
14 #include <iostream>
15 #include <QTabWidget>
16 #include <QVBoxLayout>
17 
18 namespace cx
19 {
20 //------------------------------------------------------------------------------
21 TabbedWidget::TabbedWidget(QWidget* parent, QString objectName, QString windowTitle) :
22  BaseWidget(parent, objectName, windowTitle),
23  mTabWidget(new QTabWidget(this))
24 {
25  mTabWidget->setElideMode(Qt::ElideRight);
26 // mTabWidget->setFocusPolicy(Qt::StrongFocus);
27  mLayout = new QVBoxLayout(this);
28  mLayout->addWidget(mTabWidget);
29  mLayout->setMargin(0); // lots of tabbed widgets in layers use up the desktop. Must reduce.
30 
31  connect(mTabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(const int &)));
32 }
33 
35 {}
36 
37 void TabbedWidget::addTab(BaseWidget* newTab, QString newTabName)
38 {
39  int index = mTabWidget->addTab(newTab, newTabName);
40  mTabWidget->setTabToolTip(index, newTab->toolTip());
41  mTabWidget->setTabWhatsThis(index, newTab->whatsThis());
42 }
43 
44 void TabbedWidget::insertWidgetAtTop(QWidget* newWidget)
45 {
46  mLayout->insertWidget(0, newWidget);
47 }
48 
49 void TabbedWidget::tabChanged(const int &index)
50 {
51  // A new tab has been selected, so give the focus to its widget
52  QWidget* widget = mTabWidget->widget(index);
53  if (widget)
54  widget->setFocus();
55 }
56 
57 void TabbedWidget::setDefaultWidget(QWidget *widget)
58 {
59  mTabWidget->setCurrentWidget(widget);
60 }
61 
62 
63 //------------------------------------------------------------------------------
64 } //namespace cx
void setDefaultWidget(QWidget *widget)
void insertWidgetAtTop(QWidget *newWidget)
QTabWidget * mTabWidget
void addTab(BaseWidget *newTab, QString newTabName)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
virtual ~TabbedWidget()
QVBoxLayout * mLayout
Namespace for all CustusX production code.