PDA

View Full Version : QTAbBar not displaying



Dune
7th February 2006, 16:50
My QtabBar is not displaying although it is compiling fine and showing the controls.


QTab *tab1 = new QTab("General");
qtb.addTab(tab1);
QTab *tab2 = new QTab("About");
qtb.addTab(tab2);

jacek
7th February 2006, 16:58
What is the type of that qtb variable? Do you use QTabWidget?

Dune
7th February 2006, 17:02
qtb is QTabBar

I am using QDialog because I thought QTabWidget was for putting widgets in the tabs. Ok controls are called widgets in qt.

piotrpsz
7th February 2006, 17:13
My example



layout->addWidget( d_tab_bar = new QTabBar( parent ));
d_tab_bar->setShape( QTabBar::TriangularBelow );
d_tab_bar->addTab( d_view_tab = new QTab() );
d_tab_bar->addTab( d_console_tab = new QTab() );


best regards
piotr

Dune
7th February 2006, 17:24
My example



layout->addWidget( d_tab_bar = new QTabBar( parent ));
d_tab_bar->setShape( QTabBar::TriangularBelow );
d_tab_bar->addTab( d_view_tab = new QTab() );
d_tab_bar->addTab( d_console_tab = new QTab() );


best regards
piotr

Thanks and I should inherit from QTabWidget?

piotrpsz
7th February 2006, 17:26
Thanks and I should inherit from QTabWidget?

No. In my code is all what you need :)

jacek
7th February 2006, 17:31
No. In my code is all what you need :)
Does your code require QWidgetStack/QStackedWidget to display tabs?

piotrpsz
7th February 2006, 17:34
Does your code require QWidgetStack/QStackedWidget to display tabs?

Full example (with QWidgetStack):



void MainWindow::create_work_area( QFrame* const parent )
{
QVBoxLayout* const layout = new QVBoxLayout( parent );
if( layout ) {
layout->addWidget( d_widget_stack = new QWidgetStack( parent ));
layout->addWidget( d_tab_bar = new QTabBar( parent ));

d_widget_stack->addWidget( d_workspace = new Workspace( parent ));
d_widget_stack->addWidget( new Console( parent ));

d_tab_bar->setShape( QTabBar::TriangularBelow );
d_tab_bar->addTab( d_view_tab = new QTab() );
d_tab_bar->addTab( d_console_tab = new QTab() );

connect( d_tab_bar, SIGNAL( selected( int ) ), this, SLOT( set_current_tab( int )));
}
}

...

void MainWindow::set_current_tab( int )
{
d_widget_stack->raiseWidget( idx );
d_tab_bar->setCurrentTab( idx );
}



piotr

jacek
7th February 2006, 17:43
Full example (with QWidgetStack):
[...]
I see, so in fact you had to implement your own QTabWidget.

Dune
8th February 2006, 15:30
Working for me so far. I had to set it up in inheritance mode for me and of course change some formatting to my own. I will see if I can just inherit from the WidgetStack now instaed of using QFrame.

EDIT:
Eh, I need the QFrame as a parent.

Dune
9th February 2006, 17:06
I can't get my labels to change stack position. I would assume when one is raised that it would be on top of the other plus the labels are not changing geometry.


TabDialog::TabDialog(QWidget *parent, const char *name, const QString &_filename)
: QFrame(parent, name), filename(_filename), fileinfo(filename)
{
//widget1 = new QWidget(this);
//widget2 = new QWidget(this);
tabbar = new QTabBar(this);

tabbar->setShape(QTabBar::RoundedAbove);
tabbar->addTab(viewtab = new QTab("aaaaaaaaaaaaa"));
tabbar->addTab(consoletab = new QTab("dddddddddddd"));

widgetstack = new QWidgetStack(this);

widgetstack->addWidget(label1= new QLabel("ccccccccccc", this), 1);
widgetstack->addWidget(label2 = new QLabel("ggggggggggg", this), 2);
label1->setFrameStyle(QFrame::Panel | QFrame::Sunken);
label2->setFrameStyle(QFrame::Panel | QFrame::Sunken);

connect(tabbar, SIGNAL(selected(1)), this, SLOT(setTab(1)));
connect(tabbar, SIGNAL(selected(2)), this, SLOT(setTab(2)));
//connect( this, SIGNAL( applyButtonPressed() ), this, SLOT( ));
}

void TabDialog::setTab(int id)
{
widgetstack->raiseWidget(id);
tabbar->setCurrentTab(id);
resizeEvent(0);
}
// leave this, it's for resizing the frame and then you need sizehints for that
void TabDialog::resizeEvent(QResizeEvent *e)
{
if(e)
QFrame::resizeEvent(e);

tabbar->setGeometry(200,0,200,30);
label1->setGeometry(100,50,20,20);
label2->setGeometry(100,100,20,20);
}

jacek
9th February 2006, 17:15
connect(tabbar, SIGNAL(selected(1)), this, SLOT(setTab(1)));
connect(tabbar, SIGNAL(selected(2)), this, SLOT(setTab(2)));
You can't specify parameter names or values in SLOT and SIGNAL macros.

Try:
connect( tabbar, SIGNAL( selected( int ) ), this, SLOT( setTab( int ) ) );

wysota
9th February 2006, 18:51
My QtabBar is not displaying although it is compiling fine and showing the controls.


QTab *tab1 = new QTab("General");
qtb.addTab(tab1);
QTab *tab2 = new QTab("About");
qtb.addTab(tab2);

I think the problem here was you were creating that QTabBar widget on stack and not on heap (based on the way you reference it) and it was being deleted upon return from the function.

Dune
9th February 2006, 18:59
Thanks, I redid the code. Seems to be working as the 'aaaa' label disappears when I select a tab but the bbbbb label is hidden and my labels are at 0,0 still.


TabDialog::TabDialog(QWidget *parent, const char *name, const QString &_filename)
: QFrame(parent, name), filename(_filename), fileinfo(filename)
{
//widget1 = new QWidget(this);
//widget2 = new QWidget(this);
tabbar = new QTabBar(this);

tabbar->setShape(QTabBar::RoundedAbove);
tabbar->addTab(viewtab = new QTab("aaaaaaaaaaaaa"));
tabbar->addTab(consoletab = new QTab("bbbbbbbbbb"));

widgetstack = new QWidgetStack(this);

widgetstack->addWidget(label1= new QLabel("11111111111", this), 1);
widgetstack->addWidget(label2 = new QLabel("222222222222", this), 2);
label1->setFrameStyle(QFrame::Panel | QFrame::Sunken);
label2->setFrameStyle(QFrame::Panel | QFrame::Sunken);

connect(tabbar, SIGNAL(selected(int)), this, SLOT(setTab(int)));
//connect( this, SIGNAL( applyButtonPressed() ), this, SLOT( ));
}

void TabDialog::setTab(int idx)
{
if(idx == 1) {
widgetstack->raiseWidget(1);
}
if(idx == 2) {
widgetstack->raiseWidget(2);
}
resizeEvent(0);
}

// leave this, it's for resizing the frame and then you need sizehints for that
void TabDialog::resizeEvent(QResizeEvent *e)
{
if(e)
QFrame::resizeEvent(e);
tabbar->setGeometry(200,0,200,30);
label1->setGeometry(100,50,20,20);
label2->setGeometry(100,100,20,20);
}

Dune
9th February 2006, 19:01
I think the problem here was you were creating that QTabBar widget on stack and not on heap (based on the way you reference it) and it was being deleted upon return from the function.

here is my class code:


class TabDialog : public QFrame
{
Q_OBJECT

public:
TabDialog( QWidget *parent, const char *name, const QString &_filename );

QString filename;
QFileInfo fileinfo;
QWidgetStack widgetstack;
//QWidget *widget1;
//QWidget *widget2;
QTabBar tabbar;
QTab *viewtab;
QTab *consoletab;
QLabel *label1;
QLabel *label2;

void resizeEvent(QResizeEvent *e);
protected slots:
void setTab(int idx);

// void setupTab2();
// void setupTab3();
};

Dune
9th February 2006, 19:13
Ok I am new to pointers. I can only use this '->' with pointers.

jacek
9th February 2006, 19:24
Thanks, I redid the code. Seems to be working as the 'aaaa' label disappears when I select a tab but the bbbbb label is hidden and my labels are at 0,0 still.
Did you set a layout for your dialog? Maybe it will be easier for you to use Qt Designer?


if(idx == 1) {
widgetstack->raiseWidget(1);
}
if(idx == 2) {
widgetstack->raiseWidget(2);
}
Woudn't it be easier to write:
widgetstack->raiseWidget( idx );?

Dune
9th February 2006, 19:25
Thanks and no I dont use that stuff ;)

I want using a layout but I guess I can.