Signals and Slots Editing Buttons Are Disabled (Qt Designer 4.8) - qt

I want to add custom slots to my design via Qt Designer (4.8), but editing buttons on "Configure Connection" window are disabled. How can I solve it?

You can only add custom signals/slots to subclasses of Qt classes.
As a demonstration of this, make a connection between pushButton and the top-level widget. When the connection dialog is shown, you will see that the right-hand edit button is now enabled. This is because the top-level widget will usually be a subclass of QWidget, QMainWindow, or QDialog that is defined by the application.
To add custom signals/slots to child widgets, you would need to use widget promotion, so that you can specify a subclass that will be supplied by your application. See this answer for how to promote widgets in PyQt.

Related

How to add a UI QWidget to a UI QWidget?

Completely using QT Designer. I've created a QWidget to encapsulate a collection of controls. I now want to use this QWidget several times in the QMainWindow form.
How do I 'put' my QWidget onto the QMainWindow using QT Designer only?
Shouldn't this just be a simple drag and drop operation? What am I missing?
You can promote widgets.
Simply drag and drop QWidget into your mainwindow with QtDesigner.
Right click on it and press promote to In the dialog fill in your created widget's Class name (header should be filled in automatically if it doesn't match edit accordingly) press add and promote.
Now build and run your application and you should see your widget with collection of controls.

A way to connect checkbox state to widget visibility in Qt Designer

Does anyone know if there is a way to connect a state of a checkbox in Qt to an object visibility in Qt Designer? I somewhat new to Qt and and prefer to work with Qt Designer rather than messing with the UI code manually. Qt version I'm using is 4.8.6
Any help is appreciated.
In code (old Qt 4 way):
connect(checkbox, SIGNAL(toggled(bool)), widget, SLOT(setVisible(bool)));
or (recommended Qt 5 way):
connect(checkbox, QCheckBox::toggled, widget, YourWidgetType::setVisible);
In Designer: open the Signals And Slots Editor, connect signal and slot above.
Noticed that signals and slots from Designer are reset sometimes, don't know why. Maybe it is more reliable to connect them in code on widgets setup.
Yes, you can connect the checkbox's toggled(bool) signal to the widget's setVisible(bool) or setHidden(bool) slot in Qt Designer - either in "Edit Signals/Slots" mode using drag-and-drop, or in the "Signal/Slot Editor" dock.
If using the drag-and-drop interface to add the connection, you'll need to turn on "Show signals and slots inherited from QWidget", else setVisible(bool) and setHidden(bool) will not be available for the target widget.

How to make app looks nice in Qt?

I want to know is it possible to make application fully skinned/styled in Qt I mean by that not only controls inside the application window but the mainwindow itself! like close button/maximize button/minimize button and the bar, and the mainwindow border!, is it possible to do that in Qt? and how to?
Yes it is possible. The best method in Qt is to use Qt style sheets. The Qt documentation has plenty of examples and you can style all the widgets, either by specifying a whole class such as QPushButton, or a single, named widget.
As for the items on the title bar, I'm not sure if that's possible directly, but you could certainly turn off the main tool bar that contains the minimise / maximise buttons and then implement and style your own widgets while replicating their functionality.
The second argument to the QWidget constructor is Qt::WindowFlags. You can use the flags to control the properties of a window. For example, pass the flag Qt::FramelessWindowHint to create a borderless window.
There are a few ways to do this in code. You can use the setWindowsFlag method from within your widgets constructor:
setWindowFlags(Qt::FramelessWindowHint);
If you are creating a custom widget, you can pass the flag to QWidget's constructor:
YourWidget::YourWidget(QWidget *parent) : QWidget(parent, Qt::FramelessWindowHint)
{
// ....
}
Or you can pass the flag when you create a widget:
QWidget *your_widget = new QWidget(parent, Qt::FramelessWindowHint);
There are also flags for the minimize button (Qt::WindowMinimizeButtonHint), maximize button (Qt::WindowMaximizeButtonHint), close button (Qt::WindowCloseButtonHint), and title bar (Qt::WindowTitleHint). With these flags, you must also set Qt::CustomizeWindowHint to disable the defaults as described in the documentation.
See the flags documentation for a full list and additional details.
As #Merlin069 stated, style sheets allow you to control the look and feel of the widgets within your application.

How do I add a QWidget designed in Qt Designer inside a designed QMainWindow?

I started developing an application, I designed a empty QMainWindow wit just the menu bar. and created two new QWidgets and designed the features of my application on each.
Here is the thing: How do I add and interchange the last two QWidgets inside my QMainWindow?, so QMainWindow will show one set of features of my application at once.
Perhaps you are looking for QStackedWidget
(from Qt: The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.)
You can find it insde the Containers group
Add a StackedWidget into your MainWindow, then
Directly edit the widget at present page by Qt designer(use the upper-right arrows to switch between differetn widgets). Notice that
in StackedWidget you have to create another signal sender, ex: a
combobox to decide which widget should be shown), or
If your custom widget contains some customized and hand-crafted
funcationalites that Qt doesn't have, you might need the widget
promotion. (otherwise, skip this)

How can I insert a widget into a mainwindow generated by Qt designer?

I have a Main window build with Qt Designer and I also have a widget built with Qt designer (both in a separate ui file). How can I instantiate my widget into my mainwindow at runtime?
The easiest way (using Designer) is to open your main window, drag a QWidget into it, and position/name the QWidget like you would your custom widget. Once that is done, right-click on the QWidget, and select Promote to.... A dialog will show up with the widgets it can be promoted to. At the bottom of that dialog, you can add a new widget for promotion. Type in the class name and include file information, and add that widget. Then select the entry in the list, and click the Promote button.
At the end of this process, you should be able to recompile, and your custom widget will be where you placed it in the main window.
Can't you use QMainWindow::setCentralWidget function?

Resources