Hi I loaded a css to change my TitleWindow close button using
TitleWindow {
close-button-skin:Embed("/../img/close_up.png");
close-button-over-skin:Embed("/../img/close_over.png");
close-button-down-skin:Embed("/../img/close_down.png");
close-button-up-skin:Embed("/../img/close_up.png");
}
When I try to reload the default.css the button disappears. Can anyone help me? ClassReference(null) doesn't work either.
TitleWindow {
close-button-skin: ClassReference("null");
close-button-down-skin:ClassReference("null");
close-button-over-skin:ClassReference("null");
close-button-up-skin:ClassReference("null");
close-button-disabled-skin:ClassReference("null");
}
Ok found the answer. This resets the close button skins.
close-button-skin: ClassReference("null");
close-button-disabled-skin: Embed(source="Assets.swf", symbol="CloseButtonDisabled");
close-button-down-skin: Embed(source="Assets.swf", symbol="CloseButtonDown");
close-button-over-skin: Embed(source="Assets.swf", symbol="CloseButtonOver");
close-button-up-skin: Embed(source="Assets.swf", symbol="CloseButtonUp");
Related
Using Qt Quick Controls 2, you can create a "traditional" menu bar like this:
ApplicationWindow {
id: window
width: 320
height: 260
visible: true
menuBar: MenuBar {
Menu {
title: qsTr("&File")
Action { text: qsTr("&New...") }
Action { text: qsTr("&Open...") }
Action { text: qsTr("&Save") }
Action { text: qsTr("Save &As...") }
MenuSeparator { }
Action { text: qsTr("&Quit") }
}
Menu {
title: qsTr("&Edit")
Action { text: qsTr("Cu&t") }
Action { text: qsTr("&Copy") }
Action { text: qsTr("&Paste") }
}
Menu {
title: qsTr("&Help")
Action { text: qsTr("&About") }
}
}
}
This works ok, but when the user presses on a menu and then drag the mouse while pressed, on the menus are not hovered. In order to hover over the menus, the mouse cannot be in a pressed state (using Qt Widgets https://doc.qt.io/qt-5/qtwidgets-mainwindows-menus-example.html this is not needed).
Is there a way to make the MenuBar, hover over items while the mouse is pressed?
When you did through this doc
https://doc.qt.io/qt-5/qml-qtquick-controls2-action.html
You then go to this doc and have high hopes when reading about "hoverEnabled"
https://doc.qt.io/qt-5/qml-qtquick-controls2-toolbutton-members.html
You really need these two signals entered() exited() from a MouseArea.
https://doc.qt.io/qt-5/qml-qtquick-mousearea.html
The short hopeful hack is to see if the documentation is "just wrong" and somewhere deep in the class structure they declared a MouseArea for a button and you really do get entered() and exited().
How else would you be able to implement hoverEnabled()? The "widget" has to know the mouse entered and did not yet exit. They may well be consuming that, but you should be able to dig through the source and find child entity that you can connect to the signal of.
There is not an easy way.
The underlying issue is that MenuItem is implemented as a Button.
When you press a button and release on another button, none of them register a click.
However, on traditional menus, if you press an item and release on another one, the item that registers the release is triggered.
The public API offered by QtQuick Controls 2 does not seem to offer a way to easily change this. So to get what you want Isee the following solutions:
Use Qt.labs.platform to build your menus, these will be native menus so they should have the correct behavior. However it still in a preview state and i have not tested them.
Reimplement MenuItem. Since it is part of Qt Quick Controls 2 it is easy to reimplement your own MenuItem, see Qt documentation. However, you will have to use MouseArea to catch user inputs and force the behavior you want.
EDIT
The 2nd solution won't work. In Qt once an Item (or a QWidget) accepts a press event, it grabs the mouse until it is released. So reimplementing MenuItem and adding MouseArea to them won't help.
Knowing that it seems that the solution would to reproduce what QMenu is doing: You need to have a single Item responsible for handling mouse events. So you should not let each MenuItem handles mouse events individually. Instead you should handle mouse events at the Menu or MenuBar level, process the events and manually change the MenuItems.
At this point I do not know if it is easier to customize Menu and MenuItem or to jus write your own Menu from scratch.
I'm trying to add a submenu to my MenuButton and it doesn't seem to be able to accept a Menu as a child. Is it possible to do this, or do I need to use some other kind of menu? My menu is set up like this:
class DotMenuButton: MenuButton() {
item("item 1").action {
//action 1
}
item("item 2").action {
//action 2
}
//here is where I would like a submenu
menu("sub menu") {
item("sub menu item 1").action {
//sub menu action 1
}
}
}
I am using TornadoFX but if there is a way to do this in plain JavaFX I can adapt it. Any suggestions would be appreciated.
Edit: As of tornadofx 1.7.19-SNAPSHOT the above code now works. :-)
I have committed support for submenus in MenuButton, so your code above will now work with the the latest snapshot release.
How to disable only dropdown and the fieldLabel should be enabled and dropdown should be disabled(not able to select and should be grayed out)
Let me know how we can do it by CSS?
This css will do the job. But its better to use a more specific selector.
.x-form-item-label {
opacity: 1 !important;
}
Alternatively, you can create a DisplayField instead of using FieldLabel and place it near the dropdown.
I wanted to have a collapsible widget. I used this code: How to make an expandable/collapsable section widget in QT.
I wanted the title of the QToolButton to be on the far left and the triangle icon to be on the right. I deleted the title, and moved the icon. Then I created a QPushButton and made it look like a QLabel and positioned it where I wanted the title to be. Now, I would like the title to be clickable - to have the same effect as clicking on the toggle icon would have. How do I connect these two signals?
Code for the QToolButton:
QObject::connect(toggleButton, &QToolButton::clicked, [this](const bool checked)
{
toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::UpArrow);
toggleAnimation->setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
toggleAnimation->start();
});
You can also write it like this:
QObject::connect(titleLabel, &QPushButten::clicked, toggleButton, &QToolButton::clicked);
I found that this works:
QObject::connect(titleLabel, &QPushButton::clicked, [this]
{
toggleButton->click();
});
Disclaimer: I have no idea if that is the correct way to do this.
I have a pushbutton which its background image gets changed regularly according to the packets ui receives from serial. When the user clicks the button, it becomes red with borders.
pb_Jack1Up ->setStyleSheet("QPushButton {border-image: url(:/ArrowKey/Up_Default.jpg); } QPushButton:focus {border-width: 1px;border-style: solid; border-radius: 4px;}");
Now, what I want is to give the button some effects, to make the user understand that the button is clicked. like make the button go inside when clicked, and when user releases the button border shall no longer be set anymore. However, in my case the button border remains. I cannot also set style sheet with pressed and released slots, because the background image depends on what we receive from serial.
Could anyone help me please?
You can use:
QPushButton { ... }
QPushButton:disabled { ... }
QPushButton:pressed { ... }
QPushButton:focus { ... }
QPushButton:hover { ... }
or take a look at this blog entry.
The button keepsfocus after you release the mouse. Thats why it still has the red border.
You can check that if you activate another widget of the form, clicking, or tabbing, red border dissapears.
Try using
QPushButton:pressed
instead of focus