in Qt it is possible to use sub-controls to style widgets, that are part of another widget: http://doc.qt.io/qt-5/stylesheet-syntax.html#sub-controls
For example: With QDockWidget::close-button, I can set the style for a button in a QDockWidget.
Now I want to create my own button for a Widget. It is possible to call it in the qss-stylesheet with the sub-control syntax MyWidget::my-button, too how to set these sub-control command to the button?
best regards
Related
There is a QGroupBox full of widgets, and all of them need to be disabled and grayed out.
setDisabled(true) does disable them functionally, but they don't turn gray.
What is the easiest and most proper way to turn them gray?
This should be a standard operation: text turns gray so that users can easily see that they are disabled.
QWidget::setDisabled() is yet (another) slot for the QWidget enabled property.
From Qt doc.:
This property holds whether the widget is enabled
In general an enabled widget handles keyboard and mouse events; a disabled widget does not. An exception is made with QAbstractButton.
Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out.
(Emphasizing by me.)
How widgets are displayed depends on their respective rendering as well as the (default) QStyle which is used in the application.
Concerning custom widgets (classes derived from any "built-in" Qt widget) where paintEvent() is overloaded, the custom widget is itself responsible to render accordingly to different states.
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.
I want that user could rename tabs: clicking on current tab label should turn on editable mode.
The only way I can see is to use stacked layout + scrollarea + custom widgets + stackedwidget.
Can I do it with standard QTabWidget?
And one more question. Can I create custom pseudo states (like predefined :hover, :selected etc)?
You can reimplement QTabWidget to get access to QTabBar and use QTabBar::setTabButton method. But sometimes it is difficult to adjust position of inserted widgets ;)
You can't create custom states, but you can use custom properties. See Q_PROPERTY macro and related QSS syntax. Note, that styles will not updated on property change, so you should manually call polish/unpolish to force widget to use QSS.
I'm trying to figure out how to use the QGroupBox widget in place of the QButtonGroup widget as the qt docs (link below) 'strongly advise against using it'.
https://doc.qt.io/archives/qt-4.7/q3buttongroup.html
The QButtonGroup had a handy method called QtGui.QButtonGroup.checkedButton() and I'm looking for a way to find the checked radio button contained in the QGroupBox. What is the new best practice for this?
The QButtonGroup Still exists and is in use only its implementation has changed and is no longer a Widget. In qt designer the QButtonGroup is no longer in the widget menu, you now select the buttons you wish to associate with a group and right click to add a QButtonGroup.
I have a class myTreeView which is a subclass of QTreeView, which I am using in other widget and doing layout manually. now I want to include myTreeView in the new widget using designer so that I can avoid layout code. any suggestions/reference, how to do this ?
Place a QTreeView into your layout in Qt Designer. Right click the QTreeView, click Promote to... add a New Promoted Class definition using the form at the bottom of the dialog.
i.e. specify the base class of your derived class as QTreeView, give the widget a name, and specify where Qt Design can find the header file for your derived class.
That should allow you, at a minimum, to place your widget on the form as you lay it out. It will most likely show up as a grey empty box (much like a QWidget) on the layout however when you compile and build a project using your .ui file your widget will appear.