Half of my answer was found here: How to prevent QSpinBox from automatically highlighting contents
However, the program still allows for a mouse or touch-drag to highlight the values of the spinboxes. I need absolutely no highlighting as my application is for an embedded device interface.
How do completely disable highlighting of any kind while still maintaining the spinbox up/down button functionality.
What we ended up doing was to connect a couple signals to the textEditDeselect slot.
foreach(QSpinBox* sb, ui.main->findChildren<QSpinBox*>())
{
sb->findChildren<QLineEdit*> ().at(0)->setReadOnly(true);
connect(sb,SIGNAL(valueChanged(int)),this,SLOT(textEditDeselect()), Qt::QueuedConnection);
connect(sb->findChild<QLineEdit*> (), SIGNAL(cursorPositionChanged(int,int)),this, SLOT(textEditDeselect()),Qt::QueuedConnection);
}
The easiest solution is to change the palette in Qt Designer.
Select qspinbox, click "Change Palette" and for HighlightedText choose black color. This will disable blue background, at least on windows.
Related
qApp->setOverrideCursor() method works successfully, if I want to hide mouse cursor, except one condition. If I add a dialog that is modal, and while it is shown, if the cursor is out of dialog's borders, it is shown again. Have you got any idea about the problem?
It does not matter how the solution for hiding mouse cursor is; whether by Qt or at the operating system level. My operating system is Windows 7.
You cannot hide the mouse cursor when it leaves your window (or dialog-window), because it is then handled by the window-manager of your OS. A workaround would be to constrain the mouse to your window/dialog, so it cannot leave. You will either need to look through the MSDN to find the specific windows functions to do it, or do it like in kshegunov's code example on the Qt-forums: https://forum.qt.io/topic/61832/restrict-mouse-cursor-movement/12
Qt's QMainWindow has a ability to dock windows derived from QDockWidget. It also would put one on top on the other if few of them are stacked, producing a tab bar. Whenever a QDockWidget's state changes a signal topLevelChanged() is emmitted. At this point I would like to get access to underlying QTabWidget to set an icon for a a newly added tab. How can I do it? My patience is over trying to dig the answer out from Qt's documentation and source code. Thank you in advance.
So icon I want to be on Contents/Index tabs.
Once at least one dockwidget has been tabified, the main-window will create a QTabBar to provide the dock-tabs. Each dock-area can have its own tab-bar. These tab-bars will become children of the main-window, so you can use findChildren() or children() to get references to them.
The main difficulty will be in finding which dock-widget belongs to which tab and in which tab-bar. If the dock-widget window-titles are all unique, you can just search using the tabText(). Otherwise, you might be able to use the tabData(), which Qt sets internally to a quintptr from the dock-widget.
Once you have the correct tab, you can of course use setTabIcon() to add your icon. But note that every time a dock-widget is untabified or moved to another tab-bar, the icon will be lost.
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 would like to implement a group of pushButtons like painting tool chose in Adobe Ps:
only one button can be checked at any time
keep button be down after I click it
I have used setAutoExclusive(true) to meet the first requirement. So the next step is to deal with the second... Please give me some advice or suggestion?
QPushbutton button;
button->setCheckable(true);
or just click on the "Checkable" check box in designer
Like suggested by another answer, you can create a QPushButton by e.g.
button = new QPushButton("Button text", this);
and then make it checkable with
button->setCheckable(true);
For this to have a visual effect, you need a section in your stylesheet (.qss) for
QPushButton:checked. If you have a section for QPushButton:pressed, you can just add it there, i.e. change
QPushButton:pressed {
to
QPushButton:pressed,
QPushButton:checked {
If you don't, the styling you need depend on the appearance of the button in its pressed state, which in turn depends on your operating system, so you have some guesswork to do.
I am trying to develop a functionality using Qt which I don't know whether it is possible to implement. Here is the requirement:
When the user hovers over a node (an object derived from QGraphicsItem), a window will be shown near the node, in the window there might be some histograms or buttons that can be clicked to show further information. When the mouse leaves the window, it will automatically close.
I tried to use a tooltip, because it can pop-up near the node and close when the mouse leaves it, but it can only show text. So, it still cannot work that way. I am wondering if there is another way to do this? I did lots of google search, but there is still no answer.
Thanks so much for helping me with this.
If you're ok with using a 3rd party library, Qxt provides a class that provides a tooltip that is QWidget based, which will let you use an arbitrary widget as the tooltip rather than just text.
See: Qxt::ToolTip
you don't have to use tooltip for your app
you can use or call widget or dialog, on hover mouse event
Please refer Qt Example EmbeddedDialog Example, It is advanced, But you can understand how hover Enter/Leaving events are working. I personally prefer don not create instance of Popupdialog for each item, create it if only nesessary. Otherwise create one dialog and pass its reference to all the items through the constructor initialization.
1. These are the API you are intrested on, reimplemet this.
QGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) and void QGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
2. When You create Dialog, You can pass Qt::WindowFlags as Qt::ToolTip.