Creating List of MonoBehaviours on an object - list

I have an object in the scene that has a monobehaviour attached. This monobehaviour has a public List. I want to be able to drag other monobheaviours from the project window to the inspector to fill this list so that this object can then add these monobehaviours to itself in the future to change its actions. The list shows up, but I cannot drag and drop them from the project window to the inspector - why is this? Thanks

If I understood correctly you should do something like this:
List<NameOfTheMonobehaviourScript> list = new List<NameOfTheMonobehaviourScript>();
And after that just drag the gameobjects with the scripts to the list, Unity will automatically reference the script on the gameobject instead of the gameobject itself.
Hope that this is what you meant!

Related

Qt Drag and Drop QTreeView

My TreeView has various folder with children. each child has a icon and text-name. the user can select one or more item and drag them into QMDI area. as image for my darg drop i have a local picture drag->setPixmap(QPixmap(myPixImage)). What I need is: how i make the selected item with icon and text as myPixImage dynamically.
It's easy to set the pixmap when your own code create the QDrag object, however using QXxxViews (not only QTreeView) you have only control on the QMimeData (when overriding QAbstractItemModel::mimeData()).
Therefore if you really need that, the only way I now is to subclass QTreeView, overriding (well... reimplenting) mouseMoveEvent() and the like.
If you do so, you can get the selected items when creating the QDrag through e.g. selectionModel()->selectedItems().
First of all: there's no simple way to do this. Basically because QDrag::exec is started when you (as developer) allow the start of the drag (example here) and it doesn't return until the drag is finished.
You want to change your QDrag object while dragging.
Your best option here is:
After creating the Drag object and before running QDrag::exec store the object in some pool that can be accessed anywhere in the code. Probably something like static map<QDrag *> pool
Set up a recurrent QTimer event that constantly updates the the QDrag object, which can be obtained from the pool. Do not try using Qthreads as you'll end up with some "QObject can't be moved from/to thread" error.
When the drag's ended (as user), clean up the object from the pool
Do mind that you'll have to visually tune the QTimer repeated events accordingly.

Qt Mouse Event Receiving issue

This might seem as too simple question, but I couldn't find the answer for too long, so I've decided to ask a question here.
I have a class derived from QFrame. It contains two buttons.
Issue: When I set a parent to those buttons as "this" they do show up but they have no reaction to the mouse. When I set as parent parent of my QFrame it works:
When:
m_btnCompile = new ApproxGUIMenuButton(this);
m_btnSettings = new ApproxGUIMenuButton(this);
Doesn't work
When:
m_btnCompile = new ApproxGUIMenuButton(parentWidget());
m_btnSettings = new ApproxGUIMenuButton(parentWidget());
Works
Second option isn't solution for me because I need buttons to be in local coordinate system.
Parent is generated by QDesigner. I'm working in Visual Studio 2013 if it's important. What do I need to do? Please, help.
Problem solved but I still don't know a reason. I've added new member derived from QWidget and inside it set it as parent to those buttons and it worked.

How to get UI objects to only appear in dialog AFTER button is clicked

I have a dialog that initially has several buttons, let's call them Write, View, OK, and Cancel.
The way it should to is to have the dialog upon creation only have those three buttons and nothing more.
When the Write button is cancelled, it's supposed to create a QLineEdit object in the window above the buttons where the user can enter a new string,which when OK is then clicked will be added to an external QStringList.
When View is clicked, LineEdit should go away (if it's up) and a QListView to come up instead to view everything in that list.
The problem is, I know how to use hide() to get objects that are already in the dialog to NOT appear.
but I am having trouble figuring out how to get an object not currently on the table to appear. I'm new to using Qt so it may be something easy I'm just accidentally overlooking (in fact I hope it is).
Could anyone please offer advice? Thanks!
Just create the items normally and then set:
ui->control->setVisible(false);
after you have created the UI (after ui->setupUi(this);) possibly in the constructor (in case you use code generated by Qt Creator).
And when you need them:
ui->control->setVisible(true);
Doc for this:
http://qt-project.org/doc/qt-4.8/qwidget.html#visible-prop
when using a QListView you should also have a QListModel that provides the data to it, if you only have QStrings then a QStringListModel is premade for you to use
to add a row you can do:
int rows = model->rowCount();
model->addRow(rows,1);
QModelIndex index = model->index(rows,0);
model->setData(index, string);

How to create splitter window in dialog, attach example

I am practice on splitter window, I reference to this web site,
Creating a Splitter Window in a Dialog Box in Three Easy Steps
when I build it, some thing error I cant solve it, like follow code...
Out of memory creating a splitter pane.
Error: Trying to create object which is not DECLARE_DYNCREATE
or DECLARE_SERIAL: CDialogEx.
Out of memory creating a splitter pane.
Error: Trying to create object which is not DECLARE_DYNCREATE
or DECLARE_SERIAL: CDialogEx.
the link for download this example, please rewrite the example,
splitter dialog example
the other feature, I want to create a two panel with button and static
and listcontrol item.
thanks guy.
Don't use a dialog base application. Just use the wizard. Create a SDI sample with a CFormView... integrate the splitter window later.
It doesn't make sense to me to create a dialog and to integrate all the CFrameWnd features into a CDialog...
I replaced the CDialog1 with CWnd then solved this problem.
ccc.m_pNewViewClass = RUNTIME_CLASS(CWnd);
m_cSplitter.CreateView(0,0, RUNTIME_CLASS(CWnd),
CSize(100,100), &ccc);
m_cSplitter.CreateView(0,1, RUNTIME_CLASS(CWnd),
CSize(100,100), &ccc);

how to add child window controls to CWindowImpl

How do I add simple child window controls (e.g. a button) to a CWindowImpl?
I've looked at CWindowImpl and CDialogImpl. With CDialogImpl, it appears that you just create a dialog template resource and use it, very simple. I would like to do something similar with CWindowImpl, but there doesn't seem to be a way to do it. Must I add the controls manually and position them programmatically?
Some context on what I'm trying to do: I'm trying to create a plug-in for foobar2000, a Windows audio player. I would like to create a "UI element" plugin, and in the sample code that I've looked at, a "UI element" is created via CWindowImpl. How do I add buttons to this CWindowImpl? I've tried using a CDialogImpl instead, but this gives me a "pop-up" dialog, which is not what I'm looking for.
Thanks very much in advance!
With any window, including CDialogImpl, you can add child controls by creating a new window of control class and specifying your parent window handle as a parent for new control. Additionally, SetParent API is here to re-parent any window.