How to access QHeaderView::sectionsInserted slot - c++

I wanted to know how I can gain access to the sectionsInserted slot.I need access to the parameters of that method. Since it is a protected slot I think I would need to inherit from QHeaderView. Now even if I inherit from QheaderView how would I attach that Qheaderview to my tableview ?

You can set the vertical and horizontal headers of a QTableView with QTableView::setVerticalHeader() and QTableView::setHorizontalHeader(), respectively.

You should use QAbstractItemModel::columnsInserted or QAbstractItemModel::rowsInserted signals instead. They have exactly the same signature. I believe they are connected to the QHeaderView::sectionsInserted slot.
Subclassing QHeaderView will not help you. QHeaderView::columnsInserted is not virtual, so your implementation will not be called by Qt.

Related

Is it possible to get Qlabel name from Qlabel text?

In our project, We have used Qlabels in different UIs and different classes,
such as :
ui->label->setText(label_ABC);
We want to provide label name change access to the user.
Default name already exists. If the user wants to change label name then first they change label_ABC to label_XYZ. this is saved in a database.
We want to replace lable_ABC to label_XYZ in all UI.
What is the best way to doing this?
A way to do it could be to derive QLabel to a child class (let's call it MyQLabel) which will define a setTextEnhanced() method (you can use a better name of course) which will perform the setText() and emit a signal which sends an identifier of the MyQLabel for example.
If you use this class instead of a pure QLabel and connect the raised signal to a slot that will perform the setText() over the others MyQLabel, the job is done.
This slot will be the one to handle the relation between every GUIs MyQLabel by associating the differents MyQLabel with their identifiers for example.
I hope this can help.

Accessing widgets from Window*

In my code, I have a Gtkmm Gtk::Window* and I wanna access it's widgets frequently. How can I do it?
What I mean is to see if there's any feature like Builder->get_widget(). Thanks for helps.
Not really. There are some methods for finding children of a widget, but it's a colossal pain.
Personally, I always subclass Gtk::Window and make public (or make public functions) if I need to mess with any widgets outside the class.
Gtk::Bin class where get_child() is: http://developer.gnome.org/gtkmm/unstable/classGtk_1_1Bin.html#a8e7fef9251afa541318bb53dcf3098db

Can I implement methods of a QWebView from a ui?

I use Qt designer to make an interface and I have an QWebView in it. I would like to reimplement the fonction mouseDoubleClickEvent of my QWebView.
Can I do that? I know I have to use ui->webview to access it, I know I can use the signals easily with on_webView_selectionChanged for example, but what about other methods like mouseDoubleClickEvent?
Since mouseDoubleCLickEvent is a virtual protected function, you will need to subclass QWebView and re-implement the method in your subclass. The documentation for mouseDoubleClickEvent, a method of QWidget, can be found here. After this, you will probably want to integrate your custom widget with Qt Designer. I am not familiar with the program, but this documentation might prove useful. (Edit: it appears that promoting a custom subclass of QWebView requires additional steps which are documented here and here) I do not know of any pure GUI method for creating the custom subclass you need.

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.

How to access to parent widget on qt?

I have an inherited QTreeWidget (called PackList) class and its parent is a KXmlGuiWindow.
How can I access to the parent's slots?
I've tried getParent()->mySlot() from the QTreeWidget class but I've got
error: no matching function for call to 'PackList::mySlot()'
Does anybody know the correct way? Thanks
If you know the parent's class, you will have to cast parentWidget() to that class and then call your slot. Keep in mind whether or not it's a slot makes no difference in this case. You are just calling a method.
((KXmlGuiWindow*)parentWidget())->mySlot();
You can make the call without casting by wiring up your signal to the slot.
connect( this, SIGNAL(mySignal()), parentWidget(), SLOT(mySlot()) );
Lastly, you can use QMetaObject::invokeMethod to call it if you don't want to cast it. That's probably overkill.
I'm not sure I fully understand your question.
However, you can access the parent widget of a widget with parentWidget().
Then, you should be able to call any public slot :
parentWidget()->a_slot();