Drag Text from an item of QListWidget to QLabel - c++

I'm looking for the simpliest way, using Qt Designer and a little code, to drag text from a QListWidget (apparently there are options of draggable content in Qt Designer) to a QLabel (but I can't find any droppable action option ...) so its text is set to the text of the item we dragged.
Any ideas ?
[C++, Windows, Qt5]

Well, yeah, the most straightforward idea is subclassing QLabel and reimplementing it's
void dropEvent(QDropEvent* event)
QDrag object will help you pass text from QListWidget via it's mimeData, just create one in mouse event handler.
Check similar questions or examples for more information.

Related

QTableWidget check right mouse even cell pressed

I am a beginer with QT.
I want to display menu ( copy, paste, clear) when right-click mouse btuton on QTableWidget. In mainwindow i can use mousePressEvent(QMouseEvent* event), but in QTableWidget i can't do that.
One way is to have widgets show a context menu from the list of actions you set on the widget. See QWidget::addAction() and the related functions. Set the widgets contextMenuPolicy to Qt::ActionsContextMenu to use this approach. You can also handle the menu manually by modifying the contextMenuPolicy to be Qt::CustomContextMenu and then connect to the customContextMenuRequested signal.

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,

Allow user to resize widgets at runtime in QT5

I have an application written in C++/QT5 with a QListView widget within a QHBoxLayout within a QGroupBox. There is also a QTabWidget in the main window. I would like the user to be able to resize the QListView widget by clicking and dragging and for the other items to automatically resize themselves accordingly.
I feel like this should be something that is easily done within the framework of QT5, but I can't for the life of me find a way. Even having a border on the list view that I can resize within the code of my application would be a start.
Thanks to jhnnslschnr I was able to solve this via the QSplitter widget. If you're using QtCreator as I was, you can use QSplitter simply by Ctrl-clicking the widgets you want in the splitter and then selecting "Lay out horizontally (vertically) in splitter". The user can now select the partitioning at run-time.

QT window within window?

I'm setting up a small code editor using QT and following this example. However, i'm curious on how to create windows within windows or widgets within widgets. I'm trying to achieve something similar to these:
http://i.stack.imgur.com/Vn8Ut.png
http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Download-Visual-Studio-2013-while-your-f_1431E/image_4eb5427c-1ae7-4464-9c26-2282fe8d06c3.png
Is there an example of overlaying widgets like this?
Any alternative soloution for QMessagebox for IOS development (QWidget application only)?
I gave an example of getting another QWidget to be embedded and painted on top of another one. Let me know if you have any questions about how it was done.
The PopUp flag and Qt::Tool options are also relevant.
Be sure to check out: the ToolTip property of a QWidget and the WhatsThis property of QWidget.
http://qt-project.org/doc/qt-5/qwidget.html#toolTip-prop
http://qt-project.org/doc/qt-5/qwidget.html#whatsThis-prop
There are also other ways to make borderless, focusless windows that hover and disappear quickly on command. The Window Flags and Widget Attributes in Qt are very powerful when you are looking to modify Qt Widgets.
When you parent a Widget to another widget, it will draw itself on top of the other. Then you just need to resize and position it properly.
Also subclassing existing widgets can give you more options.
Draw text on scrollbar
Also common Qt::Tools that you will find are QDockWidgets. They are awesome!
Hope that helps.
Take a look at Qt Namespace especially Qt::WA_LayoutOnEntireRect and Qt::WA_StyleSheet. Pass it as a widget attrybutes. The second option looks promising but you have to create style sheet for QWidget.

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.