PDA

View Full Version : setting i widgt visible/invisible on toggling of button



quickNitin
22nd November 2006, 11:12
greetings,
i am using a component usign multiple inhritance approach. I has got a tabWidget, a push button and a table widget. On press of a push button i want this table widget to appear and go.

here is how my code look like.

ui file for dialog


<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>TitleForm2</class>
<widget class="QWidget" name="TitleForm2" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>401</width>
<height>302</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<widget class="QTabWidget" name="tabWidget" >
<property name="geometry" >
<rect>
<x>40</x>
<y>40</y>
<width>301</width>
<height>80</height>
</rect>
</property>
<widget class="QWidget" name="tab" >
<attribute name="title" >
<string>Tab 1</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2" >
<attribute name="title" >
<string>Tab 2</string>
</attribute>
</widget>
</widget>
<widget class="QPushButton" name="pbnOk" >
<property name="geometry" >
<rect>
<x>250</x>
<y>130</y>
<width>87</width>
<height>29</height>
</rect>
</property>
<property name="text" >
<string>More</string>
</property>
</widget>
<widget class="QWidget" name="" >
<property name="geometry" >
<rect>
<x>60</x>
<y>180</y>
<width>258</width>
<height>101</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="Line" name="line" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget" />
</item>
</layout>
</widget>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections>
<connection>
<sender>pbnOk</sender>
<signal>toggled(bool)</signal>
<receiver>TitleForm2</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>275</x>
<y>158</y>
</hint>
<hint type="destinationlabel" >
<x>270</x>
<y>178</y>
</hint>
</hints>
</connection>
</connections>
</ui>


.h file



#include"ui_titleForm2.h"
#include<QDialog>

class TF2 : public QDialog, public Ui::TitleForm2
{Q_OBJECT
public:
TF2(QWidget *parent=0);
public slots:
void hide(bool);
};


and .cpp file


#include "titleForm2.h"
#include<QTableWidget>
#include<iostream>
TF2::TF2(QWidget *parent):QDialog(parent),TitleForm2()
{ setupUi(this);
tableWidget->setVisible(false);
connect(pbnOk,SIGNAL(toggled(bool)),tableWidget,SL OT(setVisible(bool)));
connect(pbnOk,SIGNAL(toggled(bool)),this,SLOT(hide (bool)));

}

void TF2::hide(bool b)
{ //control not reaching here
tableWidget->setVisible(b);
std::cout<<" "<<b<<" |";
}


i has debugged that my code is not reaching to respective commented line. I has connected this signal in designer also.

and main is




#include<QApplication>
#include"titleForm2.h"

int main(int argc, char**argv)
{
QApplication a(argc,argv);

TF2 t;
t.show();

return a.exec();
}


In this i couldn't figure outt why this signal is not getting connected.

quickNitin

e8johan
22nd November 2006, 11:52
Hide does not take a boolean as an argument.

jacek
22nd November 2006, 20:03
Is that button checkable?

quickNitin
23rd November 2006, 03:04
i redefined hide() again in my class unknowingly but i think its going to create any isssues. is it?
About checkable nature of button , i hadnot set that explicititly. I will try to set that.

quickNitin
23rd November 2006, 05:24
yes, makeing button checkable did helped and it is working.