qt delegate editor pops up with no parent - c++

I'm using a QStyledItemDelegate in QTableView. I followed tutorial http://doc.qt.io/qt-5/qtwidgets-itemviews-spinboxdelegate-example.html . No problem for this.
I just changed QSpinBox to a custom widget I designed (let's call it MyWidget). It's also working, but now, whenever I trigger a cell of QTableView, editor MyWidget is poping up as a parentless widget would do. I've been trying to understand what makes the editor appear at cell's location but without any success.
In short : I'd like MyWidget to appear at cell's location and be part of QTableView. As QSpinBox does in tutorial example. Is it possible ? If so, how can I achieve this ? Thanks
Edit
Solved : parent argument routing from MyWidget to QWidget was wrong.

Solved : parent argument routing from MyWidget to QWidget was wrong.

Related

Customizing QTreeWidget's child indicator

I have implemented a custom child indicator for a QTreeWidget as a QPushButton and still in the process of making it look like the original. My question is if anyone knows what control does Qt use for the child indicator, or is it some other control, like a customized QLabel? I have implemented it by sub-classing QPushButton with QPushButton::setFlat(true) and QPushButton::setCheckable(true). But I still see the inflate/deflate behavior of the control when I click on it, just like it happens with QPushButton. So, should I continue styling the button until I get the desired behavior, or should I sub-class another Qt widget instead?
Here's the screenshot of a typical QTreeWidget with a child indicator. I want to know what control does Qt use for it:

Custom class in qt creator

I'm new to Qt and fairly new to C++ but I need help with this issue.
I have a custom class called HybridStack and I want it to extend a QStackedWidget and a QMainWindow.
I want it to extend a QStackedWidget so that I can use as many pages as I need and I want it to extend a QMainWindow so that I could be able to make each page have it's own MenuBar with different content of menu for different page.
I want to add this custom class HybridStack to Qt Designer by
promoting it from a QStackedWidget.
Is this possible? If it is, can you brief me on how to do this? If it's not possible then what's an alternative? Most importantly, I need to use it in the Designer because I need to use qmake
You can't derive from both QStackedWidget and QMainWindow, because both of those are in turn derived from QWidget. If you did so, you'd end up with the Dreaded Diamond. You'll have to use composition instead.
Even then, I'm not sure if it would work correctly to put a QMainWindow within a QStackedWidget, since it is designed to be a top-level item (i.e. its shown directly as a window, not embedded within another QWidget). Another way of accomplishing what you want (menu bar changing when the you change tabs) would be the following:
Make your top-level item a QMainWindow
Make the central widget a custom widget derived from QStackedWidget
When the item showing in the stack widget changes, you can call QMainWindow::setMenuBar to change the menu bar. Each widget within the QStackWidget could have its own QMenuBar instance that it uses for this purpose.

Replace current QWidget to another QWidget in QMainWindow

I have some QWidget class which ui files are separate from QMainWindow ui file.
how to add or replace current QWidet which is glued to QMainWindow into other QWidget from different class and ui files on the same QMainWindow ?
If I understand you correctly, you are currently displaying one widget and upon an action, you want to hide that widget and display another one in its place.
If this is correct, you might want to look at QStackedLayout.
Add your widget headers (note that you have to generate the headers from ui and inherit) into promoted widgets in your QMainWindow.ui.
Then, You just have to insert a QWidget,QFrame, ... depending on the base class of your
widget, and right click on it and select your custom widget from Promote to.. Submenu.
Heres a link to QT manual

Creating a tree-view with buttons? in QT

I am trying to make a dialog box like below in QT, the only problem is I have no idea what the widget is called. The bar on the left is like a tree-view widget, but when you click on it, it updates the text on the right. Does anybody happen to know what the widget is called or what widget(s) are required to perform this? I am using QT C++ on Windows.
There is an example with Qt showing you how to do this.
https://doc-snapshots.qt.io/4.8/dialogs-configdialog.html
If you're using Qt Creator as IDE, you can find it under the "Demos and Examples" tab in the Welcome Screen too.
It uses a QListWidget for the selector, and QStackedWidget to control the different pages. Connect the currentItemChanged signal of the list widget to change what page should be shown. Everything you'll need is in configdialog.cpp.
If you realy need to add QPushButton into QListWidget, use setItemWidget, or into ListView use QAbstractItemView::setIndexWidget

Qt -how to know whether content in child widgets has been changed?

In QMainWindow I have 2 QSplitters. In that splitters I have QTextEdit, QLineEdits, QTableWinget, Ragio buttons and so on... I want to know if somthing has been chaged after pressing File->New menu button. Is there any general method for doing this?
Somwhere I have read that it is recomended to use isWindowModified() function of QMainWindow, but seems it doesn't work.
setWindowModified() does not propagate the windowModified flag to the parents. This bug is described here: https://bugreports.qt.io/browse/QTBUG-20150. I have just tried it and indeed it did not work.
The isWindowModified() could be useful here since according to http://doc.trolltech.com/4.6/qwidget.html#windowModified-prop it propagates up to the parent.
However, I think you would need to set this yourself. For example, if you clicked the new button which leads to some text being inserted into a QTextEdit, you still need to call QTextEdit's setWindowModified() function - which will then propagate up to your QMainWindow - and you can just check QMainWindow afterwards. (However, you wouldn't know which children were modified)
Maybe you should have a look at QWidget::changeEvent.