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.
Related
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.
I want to dynamically instantiate a QWidget and bind its "Pressed" event, either with a Qt signal or by overriding a function.
However I'm only allowed to create one new .cpp file.
I don't know how to override a C++ function dynamically, or how to change a virtual function into a Qt signal.
Is what is represented in the picture above achievable ?
The Widgets Tutorial of the Qt docs is a nice starting point.
Under Qt Widgets Examples you can find the Calculator Example, which should contain all of what you want to do.
Take the code, strip it down to what you need, use and try to understand it.
Or maybe have a look at the Getting Started section.
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.
I'm fairly new to Qt, and am trying to wrap my head around signals and slots. Though I've figured out how to create custom slots, I've yet to figure out how do update the GUI from my C++ code. I realized that the entire UI, which I created in the designer, is only written in what appears to be XML based UI code. Do I have to handwrite my own Qt C++ UI in order to update the interface, or can I somehow use C++ to update the XML based UI? I'm just looking to add a widget to the main form on a button click. Any help is appreciated. Thanks!
To add a widget to a form you can simply do
ui->layout()->addWidget(new Widget);
XML is used by QtDesigner as a mean to create, update, and persist your GUI, enabling a visual approach to development, but in the end you can build your application entirely without it.
you dont havfe to update the xml of UI . you can inherit the ui into your own class using setupUi
http://crpppc19.epfl.ch/doc/qt4-doc-html/html/qwidget.html#setupUi
now in your C++ class you can update the widgets like changing label text, lineEdit text, setting up spinbox value using Signals & slot.
That xml is used by Qt designer and outside of designer it's only used by uic as a source to generate C++ code, so everything that you do in the designer end-up as C++ code, so it can be updated (or done completely) in C++ code (you can look into the code and see that you most likely have a member called ui that is most likely a pointer, but it can also be an instance of a C++ class that is generated for you by uic, and trough that ui member you can access the widgets and layouts that you created in the designer).
A generic resource that i recommend you to read can be found here and then (if you still can't figure it out) ask a specific question about what exactly are you trying to achieve.
LE: that link contains 3 methods to use the generated code into C++ code, don't try all of them into your working project, you may choose one method or use the default one (ui member pointer)
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