QTabWidget custom draw and empty in designer problems.
I want to show an empty QTabWidget in the designer but it seems this is not possible, so I have to remove it in code?
After removing it in code I get an empty tab widget where I would like to display some text in a label in the middle of the tab widget. My question is how can I achieve this?
Re: QTabWidget custom draw and empty in designer problems.
I managed to figure this out, it seemed pretty simple.
customtab.hpp
Code:
#ifndef CUSTOMTAB_HPP
#define CUSTOMTAB_HPP
#include <QTabWidget>
#include <QLabel>
{
public:
~CustomTab();
virtual void tabInserted( int aIndex );
virtual void tabRemoved( int aIndex );
protected:
void SetLabelPosition();
private:
};
#endif // CUSTOMTAB_HPP
customtab.cpp
Code:
#include "customtab.hpp"
#include <QTabBar>
CustomTab
::CustomTab( QWidget* aParent
){
iLabel->setText( "Double click on a file segment to open it." );
if (count())
{
iLabel->setVisible(false);
}
iLabel->setWordWrap(true);
SetLabelPosition();
}
CustomTab::~CustomTab()
{
delete iLabel;
}
void CustomTab::tabInserted( int aIndex )
{
if ( count() )
{
iLabel->setVisible(false);
}
}
void CustomTab::tabRemoved( int aIndex )
{
if ( !count() )
{
iLabel->setVisible(true);
}
}
{
SetLabelPosition();
}
void CustomTab::SetLabelPosition()
{
int xpos = width() /2 - iLabel->width() / 2;
int ypos = height() /2 - iLabel->height() /2;
iLabel->move( xpos, ypos );
}
// End of file