QLineEdit extended popup - c++

Idea for widget:
By default the widget is basically a QLineEdit where the user can input text. The QLineEdit can obviously only display a certain amount of character (limit). The idea would be that once the mentioned limit is reached, the widget should be extended with a popup window which is overlayed other GUI controls (like QComboBox poup window). This popup window would then contain the text which the "QLineEdit" could not show. The poup window size would need to be dynamic to handle multiple lines. When the widget loses focus it will show the QLineEdit box and part of the original text.
What would be a good design for this widget? Would it be possible to extend an existing widget or combine multiple widgets or ?
Tried looking at the QComboBox source code but it is rather complicated.
Update:

Related

QTableView in a popup on a QPushButton click

Click the button, a table control appears next to the button, click the blank space or the content in the control to close.
I have two ideas:
With the popmenu, can click the blank space or the content in the control to close the control, but it does not meet my needs for a table-type control
New a tableview, but I don’t know how to accurately appear under the button and realize the function of clicking the blank space or the content in the control to close the control
Update:
I need to use Qt to implement a function, but I don't know how to implement it.
The functions are as follows:
Click a QPushButton, and a QTableView is displayed below the button. I can click anywhere outside the QTableView to close this QTableView
There are two things I cannot achieve:
1.How to display the QTableView below the QPushButton (must be immediately below, such as:
(source: upload.cc)
)
2.How to close the QTableView by clicking the blank space outside the QTableView
If you can make all of this in the same window, it's simple...
To position the QTableView below the QPushButton you will use Qt Designer, and setup the QTableView to hide();. And when the QPushButton is clicked, he setup the QTableView to show();.
An show(); example:
QTableView *nametable = ui->tableView;
nametable->show(); //will appears
But to close or hide(); this when clicked in a blank space I don't know how to help you...

Is there a way to attach or anchor two QWidgets together?

I'm getting started with Qt and decided to build a full-screen text editor. I want to have a button (button with arrow in screenshot) attached to a QDockWidget which opens and closes it so the button is always visible to the right side of the screen and stay anchored to it when dock is visible or resized.
My current app is a simple fullscreen textEdit set to centeralwidget in Mainwindow.
I haven't found a way to do this yet with layouts or existing addAnchor() functions so any help or direction is appreciated.
You can achieve what you want by using a container for your text edit and the button. A QWidget instance can be used as an "invisible"*** container for other widgets.
So in Qt Designer you add a widget as a central widget of the main-window, inside this widget you add the text edit and the button, then you set a vertical layout for this container widget.
Don't forget to restrict the docking widget to only dock to the right side, you can do that with: dock->setAllowedAreas(Qt::DockWidgetArea::RightDockWidgetArea); //assuming dock is the pointer to your QDockWidget.
In case you want the dockWidget to be able to dock to any side and the button to follow, you can do that too, but it get a little bit more complicated. Basically you need to connect a slot to dockLocationChanged of your dockWidget and based on where it's docked you need to set-up a new layout for the container widget to be vertical or horizontal and the order of the textEdit and the button based on the side the dock happened.
LE:*** you will most likely need to set the margins you want, since both the widget and it's layout can have them and the actual content might have higher spacing than you want.

Difference between QPushButton and QToolButton

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,

Make QLabel text selectable?

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.

Adding scroll bar to widget containing a layout in QT C++

I am new to QT and I am creating a widget that has a gridlayout. The gridlayout contains a matrix of QLineEdit widgets. The window resizes to fit the layout but when layout is large it goes off screen. When I maximize the screen, the QLineEdit widgets are resized to fit the screen and for large layouts they become extremely small.
I want to be able to resize the window without resizing the QLineEdit widgets and add scroll bars to navigate.
I tried the following with no luck:
Window->resize(QSize(500,500));
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setWidget(Window);
where window is the widget containing the layout. Also, the window closes when after executing "scrollArea->setWidget(Window);" and I dont why.
If someone can help me out I would really appreciate it.
Thank You!
For disabling the vertical resize on the widgets, why don't you just use the setFixedHeight() method on the widgets?
For the menu bar, why don't you take it out of the widget that is scrollable. You can have a layout for the window that contains the menu bar and then the widget that contains everything else (scrollable part). Is that what you are looking for?
I fixed my problem by creating a QMainWindow with the menu bar. Then created a widget which includes the layout, set the Scroll Area to the widget. Finally set the central widget of the main widow to the scroll area.