I have a QPushButton with image, i have set focus policy to strong focus but, while focusing that QPushButton it is not getting highlighted(no dot frame or default blue border)
You should take a look at the QPalette(in Qt Designer) of your QPushButton and in particular, the HighLight color which is supposed to handle this effect. Moreover, make sure you didn't define focusPolicy in the stylesheet of a parent of that QPushButton, as that could cause problems, because QPushButton would inherit that property.
Related
Im working on a little program that require a QGroupBox that have inside a QLineEdit. I want to make "invisible" the border of the QGroupBox using:
groupBoxName->setStyleSheet("border:0;");
The problem is that even the QLineEdit inside of it inherit this style.
How can I make invisible the QGroupBox border but not the QLineEdit border?
Thanks
Give an object name for the groupbox using setObjectName() function,
group_box->setObjectName("MyBox");
Then you could style it as a css object.
group_box->setStyleSheet("#MyBox{border:0
This will only affect the #MyBox
I'm new to Qt and the difference between QPushButton and QToolButton is not so clear to me.
I know that a QToolButton is usually used in a QToolBar and it usually shows only an icon, without text, but I don't quite understand the main difference between both.
Does it have any bigger difference?
When should I use QPushButton and when should I use QToolButton?
I would like to know this to use the most appropriate button, and I need to perform some GUI tests and maybe it can be relevant.
QPushButton is simply a button. QToolButton is part of a group of widgets in the QtWidgets module that operate on QActions: QMenu and QToolBar are other examples. As a result, QToolButton is much more complex under the hood than QPushButton.
Some examples of how they are different in practice:
QToolButton is tightly integrated with QAction. Changing the icon, text, or other properties of a tool button's default action is reflected on the button.
You can change the layout of the tool button contents (icon only, text only, text beside icon, text below icon). This is not possible for a QPushButton.
QToolButton supports a "split" button type: a sidebar hot zone opens a menu instead of triggering the default action.
Tool buttons can be created directly in a QToolBar by adding an action. Other widgets must be explicitly added to the toolbar.
A tool button is meant to be displayed in a grid, so it has smaller default internal margins than a push button.
QPushButton is more for "Ok"/"Close" type buttons that contain text with an optional icon.
A QToolButton should generally have an icon.
A QPushButton should always have text.
From Qt doc: http://doc.qt.io/qt-5/qtoolbutton.html#details
"A tool button is a special button that provides quick-access to specific commands or options. As opposed to a normal command button, a tool button usually doesn't show a text label, but shows an icon instead."
When i want a button in the GUI simple with only an icon, I use QToolButton. But when i want a classic button, i use QPushButton.
No big differences,
I have a QLabel and a QPushButton added to a QHBoxLayout. The QLabel has its margins set to 0 and the layout has margin and content margins set to 0. The label and button have the same background color and the button has border set to none. However, the button still looks with a brighter color than the label and there is some extra space around the button, so it doesn't look like it's "glued" to the label. I want them to look like one big widget.
In Qt, margins describe the space surrounding the layout. In newer versions of Qt, the margins on the top/bottom/left/right can be set individually through setContentsMargins().
The space between widgets in the same layout is described by the spacing property. The spacing has nothing to do with the margins. Try calling hboxLayout->setSpacing(0); This should work.
Some days ago I have coded a widget with similar behavior. To avoid problems with margins and colors I can recommend to use second QPushButton button instead of QLabel and set both buttons to be flat with btn->setFlat(true);
I have a QLabel in my application that displays error messages to the user. I would like to make the text of the label selectable so users can copy and paste the error message if needed.
However, when I use the mouse to click and drag over the text, nothing happens - the text is not selected.
How can I make the text within a QLabel selectable by the mouse?
Code
The text of a QLabel can be made selectable by mouse like so:
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
This is found in the QLabel documentation.
You can use that same function to make links selectable by keyboard, highlight URL links, and make the text editable. See Qt::TextInteractionFlag.
Designer
Search for textInteractionFlags under the QLabel menu and set the flag TextSelectableByMouse.
Here is another method, for reference...
You could create a QLineEdit subclass instead, tweaked to look and act like a QLabel,
in the constructor:
setReadOnly(true);
setFrame(false);
QPalette palette = this->palette();
palette.setColor(QPalette::Base, palette.color(QPalette::Background));
setPalette(palette);
I think the accepted answer is simpler and preferable to this though.
I have QWidget, used Lay Out in a Grid, then a QLabel, but there are some spaces between the QWidget and QLabel. How can I make them the same size and not break the layout?
I'm using this from UI editor.
When you select the widget, in the UI editor's property pane you should see the options for the layout that belongs to it (the options have a red background, and they're usually at the bottom of the list). Amongst the options are ones for setting the margin in pixels between widgets in the layout, if you set it to 0 it should solve your problem.