QCombobox and winId
-
Hi. I have the question. My program creates a list of QComboBoxes in a cycle and user interacts with some of them. When i had a few comboboxes - no problems, each combobox I created one by one manually, but now I don
t know, how many comboboxes user will need - 3 or 150. I read about WinId, that every Qwidget have and it
s unique, so after creating new QCombobox, program read his winId and write to list, but now I have a problem - I can`t read current value, that user select in it, including trying to use find() command. Can you help me with the example of using find() with QComboBox or I did all wrong and there is much easier way? Thanks.P.S. Sorry for my English.
-
Hi, and welcome to qt-project forum!!
First of all, what do you want to achieve? Why so many combo boxes?
What might be a more object orientated thought is to let every combo box handle it's own events (subclass combobox and reimplement) and send a signal if needed by the program. The program itself only needs to hold a QList of QCombo boxes and connect slots to them.
Then again, this might not be what you want, so a bit of insight to what you want to create would be helpful. -
yes there is an easier way ;) WinId is the wrong approach in this case.
Whats exactly your usecase?
How do you expect to receive the value changes? -
Thanks for your answers.
My program is part of the company software for working with our databases. My question is about situation, when users choose some options for inserting needed data to database. In the previous version of program, there were a few QTable widgets, that user fill with their data, but now one of the column must be replace with choise, like combobox have. The main issue, that user had a button "Add new row" for the tables, so program doesn`t know, how many rows will be in the end (in some cases, more, than 20).
Thanks. -
ok i think i understood you right.
so you could create a QWidget subclass which represents your row.
Each of those widgets creates it's set of QComboBoxes (for each column).
I assume you know how to get the values from QComboBoxes and/or react on value selected signals, so i wont go in detail here.
Create and place these row widgets how you like. You may also create methods for accessing a complete set of it's values at once.What i'm talking about is capsuling your QComboBoxes and break up your whole problem down to smaller pieces.
Hope you understand what i mean.
-
Hi,
Isn't this more like implementing a proper Model/View situation with some extra buttons to add/remove rows and delegates to be filled with the comboBox for the row desired?
With the "add to database" you write the data from the model to the database. Or even maybe use the database model implementation??
Maybe a picture will tell more then words. How should it look? What raven-worx says is great if the widgets are not placed in a table, but since you first used a QtableWidget I guess you want a table??
Also a column in a QTableWidget may be filled with a QComboBox, there are multiple examples of that.