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

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.

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:

How to Create Custom, Instant, Arrow-Shaped ToolTip with unique shape?

On many web-pages nowadays, you'll frequently see instant tooltips with an arrow that points to their target, similar to:
https://www.w3schools.com/css/tryit.asp?filename=trycss_tooltip_arrow_bottom
(More specifically, I'm looking for something like: https://www.youtube.com/watch?v=0Jedht9Arec)
How would you exactly replicate this in QT? I'm not necessarily looking for something super automated, just something that can be given a position to appear at, and a function call to remove it. Furthermore, if possible, it should have curved, anti-aliased corners.
I've tried using custom QToolTip, but it's behavior does not meet my standards. I've also tried a custom QDialog with a Popup flag, but it freezes the dialog it appears above.
Any recommendations on how to proceed?
As requested by two comments below, here is the code for the QDialog scenario previously referenced. Prepare yourself, it's a lot:
// Assuming "this" is the parent dialog
QDialog* popup = new QDialog(this, Qt::Popup);
popup->show();
This code blocks mouse hover events of the parent dialog (the "this" object), thus making it unsuitable as a tool-tip replacement.
You can use QWidget::setMask to specify custom shape of a widget. Additionally you'll have to set widget's window flags to include Qt::ToolTip.

QDialog with ok and cancel buttons

I need Qt Dialog with ok and cancel buttons with standard functionality, placed on the right side of its layout. I need to inherit from it and add other widgets to its layout. I can implement it myself, but maybe there is something standard, in that case I prefer to use it, since it will be more portable.
QMessageBox shows a message, I need something more general, only QDialog and standard buttons, or maybe QDialog has an option which activates them.
Subclass QDialog and use a QDialogButtonBox for the standard buttons (docs).
In case you use QT Designer, learnpyqt.com has this nice tutorial in which they describe how to build a QDialog with multiple input fields.
QT Designer can be downloaded as described here on stackoverflow in a comment.

Qt QMainWindow central widget deletion

my application requires the user to switch between several screens. The way I'm doing this is by creating different QFrames for each screen, and then setting the Qframes as central widgets on the MainWindow. The problem is that every time I call setCentralWidget(frame), the old frame gets deleted and I can't access it later. How can save that old frame so that I can access it later?
Please let me know if I am unclear in my question.
You can remove your central widget from QMainWidow reparenting it. Then, you could set new centralWidget;
QWidget* savedWidget = mainWnd->centralWidget();
savedWidget->setParent(0);//now it is saved
mainWnd->setCentralWidget(newWidget);
Also using QStackedWidget possibly would be better solution.
QStackedWidget is an elegant solution for this problem, you can find out how to use it properly here.
You can play around with .hide()/.show() on the appropriate subwidgets to accomplish this. But a better solution for your case is almost certainly to use a QTabWidget or QStackedWidget.

Qt/C++: Signal for when a QListWidgetItem is checked?

In my form I have a QListWidget which contains checkable QListWidgetItems. I'm looking for a way to capture the event of a QListWidgetItem being checked/unchecked. I don't see any such signal existing for this but maybe I'm wrong. What I'm currently doing is using the QListWidget::itemClicked() signal and checking the checkState of the QListWidgetItem, but this isn't what I want because this event happens any time the item is clicked, not just went the checkmark is toggled. Can anyone give some assistance? Thanks!
Apparently no such signal is provided, your best bet is to use QListWidget::itemChanged(QListWidgetItem* item) , and scan the resulting item->checkState(). This should be a slight improvement over using itemClicked
An extra option is to use your own QAbstractListModel with a QListView. At first this does add some extra code as you need to add your own management code . But you do get a lower level access. Basically because the QListView will ask your model what to do. It will also relay input back to your listmodel where you can hook into it.
Alternatively you could subclass QStandardItemModel and catch certain edits related to changing the checkbox.