Search code examples
qtqtabwidgetqtabbar

Why can't I compare a QTabWIdget::TabPosition with myTabWidget->tabPosition?


I am making a custom tab bar, which sits in a custom tab widget. I wish to take certain actions depending on the QTabPosition. Therefore I have the following code:

// get the parent tab widget
QTabWidget* pTabWidget = dynamic_cast<QTabWidget*>(parent());

QTabWidget::TabPosition tabpos = pTabWidget->tabPosition;

However, this results in the compiler error:

src/m-editor/octave-editor-tabbar.cc: In member function 'virtual void octave_editor_tabbar::paintEvent(QPaintEvent*)':
src/m-editor/octave-editor-tabbar.cc:69:50: error: cannot convert 'QTabWidget::tabPosition' from type 'QTabWidget::TabPosition (QTabWidget::)()const' to type 'QTabWidget::TabPosition'
 QTabWidget::TabPosition tabpos = pTabWidget->tabPosition;
                                              ^

The parent widget is the custom widget which is derived from QTabWidget.

What is the problem here?


Solution

  • QTabWidget::tabPosition is a property with a getter (QTabWidget::tabPosition()) and a setter (QTabWidget::setTabPosition()), you need to call the getter method in order to read it:

    QTabWidget::TabPosition tabpos = pTabWidget->tabPosition();
                                                            ^^