Qt and Linux novice. From the documentation:
insertItem(const QPixmap & pixmap, const QObject * receiver, const
char * member, const QKeySequence & shortcut = 0, int id = -1, int
index = -1)
I can create a qt window with a menu bar, and understand that the method insertItem(...) adds items. The argument: QObject * receiver is my problem. Everything I find seems to presume I know what this receiver item is. I have PDF versions of "C++ GUI Programming with QT 3", 4, and 5 and a find tells me that "insertmenu" and "insertitem" are not in the book.
Obviously this receiver is the target of a menu item click, but I would really like some details. Can it be any widget? Is the widget automatically shown? There are more questions.
In my current case, when the user clicks on a menu item named "Control" he should see a pop up dialog that provides the ability to set multiple radio buttons and line edits.
What I really want is a link to a page describes the concept of receiver and maybe provides a simple example.
Eyllanesc's comment is correct. We remain mostly stuck with Qt3 but have Qt4 available so I am trying to use Qt4. I forgot and referenced the Qt3 book and tried to use that. (Two reasons: Qt 3 still works and management does not want to spend money and time to upgrade. And, rumor has it that the Qt company now has non-US ownership and that is a problem for government projects. I presume, but do not know, this was not the case for Qt 3 and 4.)
But we can use Qt4, I will redirect myself.
Thank you for the reply/comment and this is resolved.
Related
I am a beginner with Qt - so hopefully this will be an easy question to answer. I have a reasonable amount of experience with C++, that part is not a problem
The purpose of my application is to do code generation, initially to make header & implementation files for classes. I quite like the Class wizard on Code::Blocks, but I reckon I can do a lot more.
I have a main Widget which has a tabWidget & some lineEdit's & some pushButtons. To preview what will eventually be in the file, I have created a new Form, with a TextBrowser in it. The new Form entry appears in the .pro file.
I would like to have the new Form displayed when I press the pushButton, & I am intending to write text in the TextBrowser based on the contents of the lineEdit's in the main Widget.
I have been looking through the documentation all afternoon, but most of the examples show either a main widget or a Form by itself. I have seen the example of the Class Wizard (which is nearly what I want to do), but I would rather a tabWidget interface. Being able to open a Form from a button is a pretty basic thing to be able to do.
For some reason, the examples page in my QtCreator help doesn't show any examples - previous versions had heaps of examples. Not sure why that is.
Do I have my terminology mixed up - should I have a Dialog rather than a Form? Not sure what the difference is.
Apologies in advance if all this is in the documentation somewhere, I seem to spend hours trolling through it, so maybe someone could provide some links - that would be great.
Suppose the new form you created along with with header and cpp file is mynewform.h, mynewform.cpp and mynewform.ui
Now include mynewform.h in your mainwindow class,
and create an object of the class
mynewform myform;
In the clicked slot of pushbutton just type:
myform.show();
or
myform.exec(); //(if you want a blocking call)
I'm rather new to C++, I have a bit of experience with MCV programming in Java. im using GTKmm on C++
What I'm trying to do is writing an application for teaching assistants to submit and edit applications to various positions, and administrators to come in view, and accept these applications.
What I'm trying to do at the begging is create 3 'frames' (I'm working on the submitting application for students only at the moment)
This first will have 2 buttons 1 for selecting if you're a student/admin
Upon clicking you're a student I want to hide this frame and show my second frame
The second frame will have another 2 buttons one for creating an application, and the other for editing applications
My core problem is that I don't understand how to switch between the frames, I've written all the code for my Model, and understand everything I want it to do however I cant seem to find how to do this...
My only idea would be to create windows for each of these, make them look all nice w/e, then when a button is pressed have that window close and a string written to file I can access to see which button has been pressed, then open a new window accordingly. Should I do it like this or is there a better way?
I think I can suggest a better/more idiomatic option for any version >= GTK+ 3.10 - which, to be fair, arrived about half a year after the accepted answer.
If you want to switch between widgets one-at-a-time without any accessories like tabs, then a Gtk::Stack seems like a better option. Because it's specifically geared for one-at-a-time presentation, without any redundancy and (theoretical) overhead from a Notebook's manual tabbing features, which you'd just be disabling straight away! It's a container with multiple children, with one visible at any given moment, and of course methods to change the active child.
You can hook up your own widgets and/or events to manage which of the Stack's children is shown. Alternatively - albeit possibly just restoring the redundancy in this case - there's a StackSwitcher companion widget, which is pretty much a vertical tab-bar as seen in the GTK+ demo and GNOME Tweak Tool.
Easiest way is to use a Notebook widget. You can hide the tabs since you will be controlling which page is showing, using method set_show_tabs(false). Put the top level widget for each of your frames in a pane using method append_page(), and switch between them using set_current_page(). You might want to hide the notebook's bevel if it's distracting, using method set_show_bevel(false).
Use signals to make a widget (e.g. "I'm a student" button) on one page do something (e.g. go to the second page). If you don't know what this means or how to do it, go through the gtkmm tutorial, it will explain this and more.
A bit too late ! But here is my try :
Gtk::Notebook is great but it is not ideal in switching between app frames on menu item clicks. Gtk::Stack, since gtkmm 3.10, exists to mitigate this. Assuming you're using glade and Gtk::Builder :
class
class AppName : public Gtk::ApplicationWindow
{
public:
//...Your app methods and callbacks
void on_mb_itemname_selected(); // The call back for our menu item click/select
private:
//Builder which will help build the app from a .glade file
Glib::RefPtr<Gtk::Builder> _builder;
//...
//Your menu item to activate a particular frame
Gtk::MenuItem * _mb_itemname;
//Your handle to Gtk::Stack which is usually the stack for the whole app
Gtk::Stack * _app_stack;
//...
}
constructor
AppName::AppName(BaseObjectType *cobj,
Glib::RefPtr<Gtk::Builder>& ref_builder)
:Gtk::ApplicationWindow(cobj),_builder(ref_builder)
{
//.. Other setup
_builder->get_widget("your_glade_id_to_stack",_app_stack);
_builder->get_widget("your_glade_id_to_menu_item",_mb_itemname);
// Connect signal_select of our menu item to appropriate signal handler.
mb_itemname->signal_select().connect(
sigc::mem_fun(*this,&AppName::on_mb_itemname_selected));
}
our callback
void AppName::on_mb_itemname_selected()
{
// Change the visible child of the stack concerned.
Gtk::StackTransitionType ttype = STACK_TRANSITION_TYPE_NONE;
_app_stack->set_visible_child("your_widget_name",ttype);
// Note that widget name is not widget glade id.
// You can set your widget under name Packing -> Name
return;
}
I am developing an application for my Nokia N8 running Nokia Belle and would like to add buttons in between the left arrow button and the menu button on the bar at the bottom of the screen.
An example of what I mean can be seen when playing a station in the Nokia Internet Radio application, which, I understand, is a Mobile Qt Widget Application (not Qt Quick).
After searching around (http://www.developer.nokia.com/Community/Discussion/showthread.php?233396-QMenu-in-Symbian-Belle-in-Qt-C), I tried this code, but the button does not appear:
QAction *pDeleteButton = new QAction(style()->standardIcon(QStyle::SP_TrashIcon),QString(tr("Delete")), this);
pDeleteButton->setSoftKeyRole(QAction::NoSoftKey);
addAction(pDeleteButton);
I put this code in the constructor of the mainwindow.cpp.
Thank you for your help!
I am no expert in programming for mobile phones, but the QAction you are creating has no parent widget. If you look at the example you are linking, you will find that the original poster assigned a menu for the action via setMenu(). Did you try something like this already? If so, I would suggest you add some more context to your code and maybe a minimal example.
hi i want to make an application for nokia in nokia qt sdk.
so please help me how to navigate one page to another page in qt C++ when user press the button in one page.
There's no page concept in Qt, but you can simulate it with other widgets or components. A couple of examples:
Using Qt Desktop Widgets: http://wiki.forum.nokia.com/index.php/Create_a_page_based_UI_with_QStackedWidget_and_QToolbar
Using Qt Quick: http://doc.qt.nokia.com/4.7/declarative-modelviews-visualitemmodel.html
In Qt Quick you can also do it by changing properties like visibility or position of elements like rectangles.
And there are other ways to do this, search for examples in Forum Nokia Wiki or in Qt DevNet.
Just write in click event of button:
manwindow *mainwindow2 = new mainwindow();
mainwindow2->showExpanded();
There is also the concept of a wizard in QT:
http://doc.qt.io/archives/qt-4.7/qwizard.html
I'm not sure if that is what you are looking for as far as look n feel, but it is pretty convenient. You simply add pages to the widget itself and it will create the "Next" and "Finish" buttons for you as well as the page navigation.
Beyond that, do as Mkfnx suggested and use a stack widget or just have a dynamic dialog where you subscribe to your button events (using the connect() ) function and hide/show your widgets as you wish.
Having seen earlier existing discussion on "stackoverflow" forum about designing and managing menus and actions under an application being designed & developped under Qt Creator (see "How to connect menu click with action in Qt Creator?" : How to connect menu click with action in Qt Creator?), I'm afraid I have same questions about action buttons in a toolbar I'm trying to create & populate with Qt creator...
So, let's go !
(1) I create at least one action in the Action Editor...
(2) I drag&drop that action to the toolbar
(steps 1 & 2 are ok, no difficulties with these ones, although it is a quite unusal way of doing such things for me, because other UIM designing tools usually propose inverse steps 2 & 1 to do the same, which is more "natural" in my opinion, but, I know, many many things exist and co-exist in our world of software designing & programming...)
=> (3) How to associate (connect) the function (which I'm going to implement) that is supposed to be called when clicking the given toolbar button ?
I mean, how to connect the "triggered" signal for the given action (toolbar button) to the desired slot (function) to be implementing later... ? Is it possible to do such things with the "Signals and slots editor" inside Qt Creator, or do I have to call "connect()" by myself somewhere in the code to achieve this ? Many thanks in advance for any help/suggestion/detailed example for perfect beginner at this point...
In fact, I would to know wether it is possible not to call connect() by myself for such need and wether Qt Creator will create slot (function) prototype by itself or do we have to create such slot (function) prototypes by ourselves before Qt Creator can take the new slot (function) prototype into account and really assist/help user/developper in this usual/normal UIM design step / designing capability... ?
Best regards.
Alain-Pierre
If the QAction is a member if your window, then the normal
QMetaObject::connectSlotsByName(SettingsDialog);
...will connect an action's trigger signal with an appropriately named slot method. This is normally called automatically by GUI classes created using the designer. So if the action is named actionSomething for example, creating a slot in your GUI class with a signature like:
void on_actionSomething_triggered();
...will mean that you don't have to manually connect the signals and slots.
Also, right-clicking on the action in the action editor and selecting 'Go to slot...' will allow you to create a slot function for any signal that the action may emit.