setting i widgt visible/invisible on toggling of button
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
Code:
<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
Code:
#include"ui_titleForm2.h"
#include<QDialog>
class TF2
: public QDialog,
public Ui
::TitleForm2{Q_OBJECT
public:
public slots:
void hide(bool);
};
and .cpp file
Code:
#include "titleForm2.h"
#include<QTableWidget>
#include<iostream>
{ setupUi(this);
tableWidget->setVisible(false);
connect(pbnOk,SIGNAL(toggled(bool)),tableWidget,SLOT(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
Code:
#include<QApplication>
#include"titleForm2.h"
int main(int argc, char**argv)
{
TF2 t;
t.show();
return a.exec();
}
In this i couldn't figure outt why this signal is not getting connected.
quickNitin
Re: setting i widgt visible/invisible on toggling of button
Hide does not take a boolean as an argument.
Re: setting i widgt visible/invisible on toggling of button
Is that button checkable?
Re: setting i widgt visible/invisible on toggling of button
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.
Re: setting i widgt visible/invisible on toggling of button
yes, makeing button checkable did helped and it is working.