tags:

views:

128

answers:

2

Hello,

I am a Qt beginner and working with Qt Designer to develop some small UI elements. I read http://doc.trolltech.com/4.5/designer-using-a-ui-file.html to use these GUI elements in my code and using multiple inheritance approach.

I am introducing bookmark feature which somewhat look like http://img293.imageshack.us/img293/3041/screenshotyb.png. Now the problem I am facing is How can I show all existing bookmark folders in the drop down(say folders are in a QVector). So my main problem is how can I pass some inputs to the UI element.

I think I'm clear, please let me know if further explanation is required. Sorry for adding links directly, rich formatting in my browser is not working.

EDIT : As some suggested, I have to go via code, but in that case is it possible that create all other components like textEdit, labels, buttons and add combobox using code. Because I have already developed code for bookmarks and adding folder feature in already existing thing.

Thanks For suggestions. Finally I came up with the solution. I was using multiple inheritance implementation of UI file generated by QT Designer. So solution look like :

Dialog.ui will be UI file generated by QtDesigner
//bookmarDialog.h
#include "ui_Dialog.h"
class BookmarkDialog : public QWidget, private Ui::Dialog
{
Q_OBJECT

 public:
     BookmarkDialog (QWidget *parent = 0);
}

//bookmarkDialog.cpp
#include "bookmarkDialog.h"
BookmarkDialog::BookmarkDialog()
 : QWidget(parent)
{
   setupUi(this);

    QList folders = getAllFolders();
    comboBox->insertItems(0,folders);//comboBox is defined in UI file
}
+1  A: 

With Qt Designer, you can add items to a combo box (double-click on the combobox to show up the editor). But if your folder list will vary, you'll have to do it by code.

Have a look to QCombobox documentation (Qt doc is really good).

How are your storing your folders in the vector ? As strings ?

Il your QVector is containing strings, you can easily convert it into a QStringList and use it to populate your combobox :

QVector<QString> FolderList;    
myComboBox->addItems(FolderList.toList());

Then, you can connect the signal currentIndexChanged(const QString&) of your QComboBox to a slot to do something when the folder has changed.

Jérôme
thanks, I got it working
GG
A: 

I think you have to do it in code. You can fill the combo box in the designer as soon as you are using static values. It is something you are doing dynamically like obtaining the bookmarks folders then you have to do it in your business logic code.

Maybe QtDesigner has been improved since the last time I used and now is possible to do complex things like that, but even in that case, from my experience, I would recommend you not to depend so much of QtDesigner. If you want to do complicated things is faster to do it in code and you will commit less mistakes and will have more control over what you are doing.

You can set the values to the combo box like this:

Suppose the vector contains the folder names as strings and is called folders.

for (int i = 0; i < folders.count(); i++)
{
comboBox.addItem(folders.at(i));
}

If this is not what you are looking for give me a comment and I will try to help.

cnebrera