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
}
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.
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.
Related
The "File >New >Other..." command of the IDE environment, shows the following image:
In the image, two areas (A) and (B) are observed. I am interested in using area control (B).
I assumed it was a TListView control, but I haven't been able to achieve similar view options as above. Other people have suggested that each of the displayed items (icon, title, and descriptive text) can be inserted inside a common container (TPanel, TFrame) and "stacked" inside a TScrollBox, a possible solution, but I think the Delphi folks may have used something more optimized.
Does anyone know which component has been used to generate that view? Or, does anyone know how to generate such a view?
It is a component called TControlList: https://docwiki.embarcadero.com/Libraries/Alexandria/en/Vcl.ControlList.TControlList
For example, I wanted to have a popover or something that would let me choose from a table (say, like the periodic table, IPA chart, etc.…) in a similar style as a graphical NSDatePicker. In addition, how could I make it select multiple cells at once?
Is there already a default Cocoa way to do so? If not, from what class could such a thing be done and maybe some pointers on from where to proceed?
(I apologize if this is another common question, but I couldn't find it on my own.)
It is very surprising, but on a lot of points, I think that OSX's GUI is very limited unlike iOS.
So, I'm afraid that you have to create your own component from scratch.
Or you can have a look at these open-source controls written for OSX :
For choosing a date : You can use MLCalendarView (Calendar-OSX) available on Github.
For displaying a TableView, with multiple selections (very similar to UITableView) : you can use this great open-source component : PXListView available on Github.
We have an in house button control, and quite frankly it sucks. I'd like to replace it but I don't want to go onto every form in our project and delete/add a new control. It seems to me that if I design a new button that has all the same properties as the old one then I ought to be able to give it the same name as the old one and just replace all the reference lines in the vbp files to point to the new control.
Has anyone tried this (better yet have you heard of a tool that will do it for you) and if so what 'gotchas' should I be on the look out for?
Thanks!
The *.vbp files are one place you'll need to change. There are also references to the used control libraries in the files containing GUIs -- that's form (*.frm), control (*.ctl), and property page (*.pag) files. These files are in a plain text format and you can see the references at the top. They look like this:
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Those refs will need to be added or updated in all relevant files if the new control is a compiled OCX. If it's in the same project I don't think it needs any reference there, and if it's in a different project in the same project group I'm not sure. Save a test form with the new control to see.
Note that you don't have to keep the same control class name. Inside the *.frm/ctl/pag files, instances of individual controls on them are represented by a simple format like this:
Begin VB.CommandButton Command2
Caption = "Cancel"
Height = 375
Left = 2460
TabIndex = 1
Top = 2400
Width = 1455
End
The syntax of the first line there is "Begin LibraryOrProjectName.ClassName NameOfThisInstance". So, provided the offending control's name is distinctive it should be easy to search & replace references to it both in the BASIC source and in the GUI layouts. You might want a plain text editor that can perform search and replace across multiple files (Notepad++ is one).
Some control properties are stored like this:
Picture = "frmMain.frx":292F
These correspond to the *.frx, *.ctx, and *.pgx files, which contain binary data for the values of certain control properties. I don't think these files should need altering or cause any problems. They don't appear to contain control names.
Use a full compile (Ctrl+F5) to be sure no problems linger in parts of the source afterward.
Never tried it. Good luck.
There is only one tip to be added to the accepted answer.
If you need to replace any generic VB control with 3rd party or custom ActiveX control you must replace the:
BeginProperty Font
with
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Omiting to do so results with run-time error 713 when trying to edit/open the form.
If there is no BeginProperty statement in the block then control uses default font and this replacement is not needed.
An additional scenario to look for is if the classes in the OCX are referenced directly in code.
In other words, if the control class was ABCButton then you need to look for ABCButton in all .BAS and .CLS files as well, and make appropriate changes.
This is easy in .NET (not my question) but I'm trying to figure out if it is possible to simply change the text of a string in a Win32 list box control given an index.
There is a GetText function that takes an item index but nothing to change the text of an existing item/string. My workaround will be to remove it and add it back in the box (which is also a weird prospect since there is no single command to add a string + item data -- these must be done carefully by inserting the string and then setting the item data on the index of the inserted string, which is tricky (not possible?) with sorting active).
Yes, the lack of a LB_SETITEMTEXT message is a bit weird.
You should put your Delete+Insert+SetData calls between calls to WM_SETREDRAW...
At the risk of being off topic...
I tend to use the ListView control all of the time. You'll want it in report view to mimic a listbox, and, as a plus, it supports multiple columns.
Oh.. and it has a LVM_SETITEM Message :)
http://msdn.microsoft.com/en-us/library/bb761186(v=VS.85).aspx
Although this question is old, but I think this documentation presented by Microsoft will be able to answer anyone questions based on this one.
So according to Microsoft documentation which you can find here
Changes the text of a list-view item or subitem. You can use this
macro or send the LVM_SETITEMTEXT message explicitly.
void ListView_SetItemText(
hwndLV,
i,
iSubItem_,
pszText_
);
And it also presents other macros for managing the list box. You can build a wrapper around this macros to simplify handling list view controls, etc.
I am working on Win32 dialogs with various controls like Static Text , Checkbox etc and all the strings need to be localized for different languages.
I have designed the dialogs for US intl . But when I put localized strings those, not fitting properly and I have to change layout for each intl.
Is there a better way to do this?
Can I create one dialogs with one layout that should work with all Intsl???
I remember reading somewhere that, during initial layout of GUI resources at MS, they create the dialogs initially in German, and then double check the layouts at least in English and Japanese.
Once a dialog layout accommodates those three languages, it typically did not require further layout changes.
You could consider using ShowHTMLDialog. If you can work out the black magic of getting data into and out of the dialog HTML does have the advantage of controls that automatically scale to accommodate their text bounds.
In the past I implemented the following derived class from CDialog called CLanguageDialog. Then I called loadLanguage() in the OnInitdialog(). Then all my dialogs in my application would derive from CLanguageDialog instead of CDialog.
void CLanguageDialog::loadLanguage()
{
CWnd *pChild = this->FindWindowEx(this->m_hWnd, NULL, NULL, NULL);
while(pChild)
{
theApp.languageLoader.loadStringForWnd(pChild);
pChild = pChild->GetNextWindow();
}
}