I've recently started lerning Qt and I'm facing the following problem:
I want to create sth like a chessboard (empty, doesn't have to do anything for now) - I've drawn a simple interface, but in the middle I need to make a chessboard itself (let's say it will be made out of small QTextBrowsers).
The problem is that the size of chessboard must be specified by user. So, drawing 16 fields and giving them unique objectNames is easy, but I have no idea how to:
generate those fields 'dynamically'
generate unique names for them, so I will be able to refer to them later in code eg. field_1_1, field_1_2, field_1_3
Thans in advance,
So what I think you want is a two-dimensional array of fields. That way you can reference the correct field without knowing the name.
More specifically Qt provides QLayoutGrid which, although not a two dimensional array, will give you grid access to widgets by using the itemAtPosition method
Related
There are two main panels used for different purposes. One of the panels is used for making some drawings, using dc(Panel-D), the other one contains some buttons for getting user inputs(Panel-I). The issue is about the placement of these two panels. I am trying to place Panel-I over Panel-D as shown below(like always on top option). The difficulty in this matter, I couldn't put Panel-I in Panel-D, because we can't intervene the drawing functions on Panel-D.
I tried using different techniques with various types of wxSizers and wxSizerFlags, but couldn't get the desired orientation/placement. I would be grateful to any suggestion.
You should have no trouble with this if you create Panel-I as a child of Panel-D. You can then position it in any way you want: either manually (e.g. if its position is fixed), or using sizers.
In specific, how do you take elements/models that are added to an XRObservableCollection and use them to generate rows/columns in XAML listbox?
I have tried to do this on my own, but my listbox remains empty, despite having elements added to my collection.
Note: This menu is being designed for a Windows Embedded Compact 7 device using VS2008 and Silverlight for Windows Embedded, so many features available in WPF do not apply to this environment.
What i have done is initialize the model of the element i want to display in the listbox as follows:
DispCh->Initialize(ChannelNum,ChannelName,InputType,DispRange_Low,DispRange_High,MovingAvgFilter,EngUnit);
By substituting values in for those variables, you are defining what to display in each column of the listbox (implying that 1 row of the listbox will contain 6 columns; display range high and low are in 1 column).
Now i add this model of my element to the collection as follows:
pMainPage->m_pDispChModelCollection->Add(DispCh);
This works fine as when i check the collection count after adding, it increases.
Now, i believe that i have done the binding correctly to take the collection and convert it into the listbox. To do this, i do the following:
XRValue value;
value.vType = VTYPE_PROPERTYBAG;
value.pPropertyBagVal = m_pDispCh_Model;
m_pReviewModeDispCh->m_pReviewMode_ChList->SetDataContext(&value);
m_pDispCh_Model->Set_ChannelCollection(m_pDispChModelCollection);
where m_pDispCh_Model is the model class that contains all the xaml initialization and binding, m_pReviewModeDispCh is the class definition for the XAML menu, m_pReviewMode_ChList is the IXRPtr to the XAML listbox, and Set_ChannelCollection takes m_pDispChModelCollection and passes it to m_pRevChList which is the following:
TBoundPointerProperty<IXREnumerable> m_pRevChList;
hResult = RegisterBoundProperty(L"ReviewModeDispChList", m_pRevChList);
Now, i could post the code that shows what i did for the xaml menu, the c++ code for defining the xaml class, the c++ class for the element model, and the c++ code where i use these class methods, but it wouldnt follow the MVCE, so instead, i'd like to see if the idea behind steps i am doing are correct as far as the code i have provided or at the very least if someone could point me in the right direction regarding generating listbox grids from C++ code.
I am using feathers ui components for starling to create an app which has drawers as navigation menu.these drawers have feathers list as data providers. There are particular elements on this list that need to be unique, that is they must have a unique font color to distinguish them from the rest.
so my question is: is there a way to customize the look of specific elements within the same list? Say, a list with 4 elements, each one has its own font color.
Thanks a lot for your help in advance, any comment could be helpful :)
Yes, there is. I've done it an year ago, but things shouldn't be that different. You must set appropriate let's call it type within the data you pass to the item renderer, Then you create custom item renderer, which has init and update function. There, you can check what's the type and construct the view differently - change font or whatever you want.
And here are some nice readings on the topic, which will definately help you: http://feathersui.com/help/item-renderers.html
I want to display hierarchical Data with a QML-Listview. This means that I have different Cpp datamodels, that have the following structure:
Section 1
Subsection 1
Item
Item
Subsection 2
Item
Section 2
The number of subsections is different in every model, so that I'm looking for a general solution to display that data in a flat list like that:
Section 1
Subsection 1
Item
Item
...
I'm using Qt 4.8.2 with Qt Quick 1.1.
What I figured out till now:
The QML ListView cannot display hierarchical listmodels
There are different solutions to display tree-structured extendable lists with multiple Listviews, but that's too complex for my models
I can make my model flat by using a Abstract-Class insert different Object types in a flat list, but that would be a lot of work, cause I had to insert lots of loops
Till now I found one solution provided by blackberry cascades, but I can't use it because I have to run my application on Embedded Linux:
Cascades Vegetables Data Model
At this moment I'm thinking about to write my own ListView with Cpp, but I would really like to avoid that because It will be a lot of work to implement that.
I'm new here at stackoverflow, so please let me know if I have to give you more informations.
Thank's in advance.
Quperman
EDIT 05.08.2014:
Temporary Solution:
Since It seems to be hard work for me to implement my own Cpp TreeView, I found another easier solution:
I created an abstract class AbstractItem with an attribute ItemType (enum), that has the following values:
Item
Section
Subsection
...
What I now do is the following:
I inherit my Section and Item classes from my new class AbstractItem. Now I put QList into my QAbstractListModel and appended the items, sections, subsections...
I can now provide different data in header and item by implementing the data() function with a switch over ItemType. depending on the ItemType I can do a reinterpret_cast to access the data.
Now I have a flat hierarchy that works for me. Sadly I can't use the class hierarchy, but at this moment it seems to be the fastest solution.
15th May 2015 We got beta version of Qt 5.5. See its features. Take a deep breath... Now you can use TreeView component in QML!
Take a look at snapshot for Qt 5.5 documentation.
I've been reading about Qt's Model/View framework. I find it really helpful on working with tabled data like tables from a database. My question is: will it be useful for non-table data like property list or just some bunch of data of various types? If so, how should I approach it?
The goal is to come up with an editor for some property list like data. The list is constructed at runtime and the elements are of various types (numbers, strings, booleans, and file paths, to name a few). Each element is basically a name-value pair. The name, type, and restrains (limits for example) for each element are defined at compile time. They will be assembled at runtime into different lists depending on user input. And the list of elements can change during the edit session.
The UI will most likely be combination of various pre-designed widgets assembled according to user input. They may not be list or table views.
Some pointer to design pattern or examples are also much appreciated. Thanks.
I don't see a problem with MVC framework in QT for doing that.
Basically the difference between a standard table display and this is that you create a list dynamically akin to a map of:
QMap<QString, QVariant> property_map;
You can do a:
QList<std::pair<QString, QVariant>> property_list;
which you can then use to display in a table the property. The best way would probably be:
struct {
QString prop_name;
int prop_type;
QVariant prop_value;
};
QVariant basically will provide you with a single abstraction class for data storage and it is actually what's being returned by the data() function inside the QAbstractItemModel which you might be reimplementing.
So basically you will take a property list and boil it down to the same table like data as the database.
AMENDED
If you have a Widget that you want to have this widget populated with other predefined widgets you are quite likely to have multiple problems unless widgets are of same or well defined size.
What you can do is in you Display widget define a layout like: QGridLayout or other possible layouts and then add your other widgets to it using some set of parameters, which could be done but can be somewhat of a pain.
The other approach that you may take is to place all property widgets up front on the display UI and simply turn the ones you need on and the rest off, but this only applicable if you have a well defined limited number of pre-designed widgets.
I've been using Model/View framework for quite some time now and I usually implement my own models with a backend based on Qt containers (vectors, list, etc). Even if data eventually comes from a database, working with (e.g.) a vector of database ids can dramatically improve performance (and sometimes is the only way you can do).
This trivial example from Qt docs (see "Creating a Custom Model) is the point where I started and shows how to use a QStringList as a backend for a custom model.
Once defined your model you can define your custom Views, which will draw arranged widgets based on the content of the model underneath.
When the model change, your view will change accordingly rearranging widgets when necessary.
Leveraging QVariant capabilities you should be able to render the proper widget for every datatype (e.g. a QSpinBox for a float a QComboBox for a QStringList, and so on...)