PDA

View Full Version : QTabBar and connect..also QTabWidget



salmanmanekia
17th April 2010, 19:27
Hi
I am trying to use a connect statement in a QWidget class on a tabBar declared in this class,i have included other class to this class and in slot i want a member of that class to be called ,so below in the code are two connect statements and both dont work


#include "NineSilicaWidget.h"
class NetworkInterface : public QWidget
{
..
QTabBar *tabBar;
NineSilicaWidget *nineSilica;
..
..
connect(tabBar,SIGNAL(currentChanged(int)),this,SL OT(setEnabled(bool)));

connect(tabBar,SIGNAL(currentChanged(int)),nineSil ica,SLOT(someSlot()));
..
}
Also,if any one can clarify me the difference between QTabBar and QTabWidget...i dont get the idea clearly from the docs

salmanmanekia
18th April 2010, 14:04
I tried to follow the 4 points of how to create a tab in QTabWidget:

The normal way to use QTabWidget is to do the following:

1. Create a QTabWidget.
2. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
3. Insert child widgets into the page widget, using layouts to position them as normal.
4. Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.


#include "NineSilicaWidget.h"

class NetworkInterface : public QWidget
{
Q_OBJECT

public:
NetworkInterface(QWidget *parent = 0);
~NetworkInterface();

private:


QTabWidget *tabWidget;
}

NetworkInterface::NetworkInterface(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);

setFixedSize(700,500 );

tabWidget = new QTabWidget(this);

tabWidget->addTab(new NineSilicaWidget(),"NineSilicaWidget");
}

NineSilicaWidget::NineSilicaWidget(QWidget *parent)
: QWidget(parent)
{
//ui.setupUi(this);
..
runButton = new QPushButton("Run");
..
}

But in the output only the tab is shown and noo push button.. :(

salmanmanekia
19th April 2010, 14:29
Any one ??

norobro
19th April 2010, 22:42
I haven't used QTabBar and I also had trouble understanding the docs, but from playing around a little with QTabWidget and QTabBar things became clearer.

This is my conclusion: You can't add a button with QTabWidget::addTab() only an icon and/or a string. So you need to create a QTabBar and use QTabBar::setTabButton() to add your NineSilicaWidget. Then add your new QTabBar to your QTabWidget with setTabBar().

As I said above I've only tried this in a simple experiment so no guarantees.

HTH If you need more detail post back.

salmanmanekia
20th April 2010, 13:41
I wont be giving time to this task for the next few days as i am busy with other things but once i will have anything to share i will come bak..Thanks for the reply..

salmanmanekia
2nd June 2010, 13:53
i have started working on the same project after a month or soo..and after reading the Tab docs what i understand is that if you are using TabWidget then you can display the tabs and its widget and you dont necessarily need to use the QTabBar with QTabWidget and vice versa...Still i am stuck while i am using QTabWidget and it does not works and am confused what is best in my scenario ,a QTabWidget or QTabBar...