qt - Accessing widgets which are members of a GridLayout -


I am a newbie QT developer (about a month) and I searched the net to solve my problem but something to me did not get . Maybe, I did not know how or what to ask about it. Therefore, I will present the problem which hates me for a few days.

I make a form dynamic with the following commands:

  QWidget * window = new QWidget; QGridLayout * headerlayout = new QGridLayout; QGridLayout * bodylayout = new QGridLayout; QGridLayout * Layout = New QGridLayout; QLabel * countrylabel = new QLabel; QComboBox * countrycombo = new QComboBox; Country & lt; & Lt; "" & Lt; & Lt; "England" & lt; & Lt; "Germany" & lt; & Lt; "Greece" & lt; & Lt; "Italy" & lt; & Lt; "Netherlands"; Countrycombo-> AddItems (country); Countrylabel- & gt; SetText ("Χώρα"); Connect (country combo, signal (current index change), this, slot (country selected)); // Suppose that 8 additional widget handles out here- & gt; Advert (country label, 0,0); Headerlayout-> AddWidget (countrycombo, 0,1); // here body part QLabel * label0 = new QLabel; QLabel * label 1 = new QLabel; Label0-> SetText ("LABEL1"); Label1-> SetText ("& lt; p> LABEL2 "); // Assume that there are 10 labels here and there are 8 additional commands given below. Bodylayout- & gt; AddWidget (label0,0,0); Bodylayout- & gt; AddWidget (label1,0,1); // Cleaver Part for here (int i = 1; i  Adlayout (header layout, 1,10,0); Layout & gt; AddLayout (bodylayout, 10,10,0); Window & gt; SetLayout (layout);  

With this code, I create a beautiful dynamic form, which there is nothing to worry about. My problem is described by the following question:

-How can I use widgets in the CLEVER part to change or read my properties (eg for the current index, spinbox etc. for the combo box) Price) What I want to do is select the country combo (at the top), then change the values ​​of the second combo on the basis of the first combo value (not mentioned here, in the headlined) and after that, the value change "Read" values ​​from the spin box to make some SQL "magic" on the combo box in the cleaver part and in the clearing part.

I have also read about signals and slots, but the problem is that the object name or address within the CLEVER part.

I read about making a QList, but I do not know that this is a good idea.

Thanks Nik

You use any QObject instance using the following code Can:

  QObject * object = parent - & gt; SearchBlind & lt; Class * & gt; (ObjectName)  

So what you need to do in your code, define an object name when creating your widgets when you put it on your QGridLayout, it becomes a parent for them So, you can do something like this:

  countryCombo-> SetObjectName ("Country"); ... QComboBox * combo = headerLayout-> Find & lt; QComboBox * & gt; ("Country");  

Or you can use your own layout - it does not matter.
The second option is when you use slots, which is when the widget emits a signal. If you want to use a widget sender, you can use the following code:

  QComboBox * combo = qobject_cast & lt; QComboBox * & gt; (QObject :: Sender ());  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -