QPushButton text offset - c++

I'd like to have a Qt widget (QPushButton), in which caption starts(!) from the center. How can I achieve it? I use Qt 5.12.x, C++, Windows. Is rewriting paintEvent the only way? I'd like to study "math" sample for it.

Related

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.

Groupbox alignment of title in qt doesn`t work. Why?

I created a simple MainWindow form in Qt 4.8.4 designer, in preview title is placed in top left corner as it should be, but when i use this form in a simple program which writen in Eclipse with QT plugin, the title placed straight at top top center which is not right. When i use ui.groupBox->setAlignment(Qt::AlignRight); or left before show(), nothing happen the title stays at the center. What may cause this? Program is minimalistic and there only group box and nothing else.
Have you tried setting a style sheet to it like this:
ui->groupBox->setStyleSheet("QGroupBox::title {subcontrol-position: right;}");

How to make a Qt widget resizable [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I add resizable widgets in Qt Creator?
I am using QTreeView and QListView and i want to make them to be sizable i.e. when i go the top end of the QTreeview the pointer should be transformed into a vertical arrow which allows me do a up resize by mouse drag and drop, a feature that is seen on many application nowadays.
How can be achieved this? Thank you.
You can put your widgets into a QSplitter.

MFC equivalent of Qt QVBoxLayout widget

I'd like to know how to position MFC controls in the dialog so that they stretch to fill free space in the dialog. In Qt it is possible to nest QVBoxLayout and QHBoxLayout widgets, I'm looking for something similar in MFC.
Additionally I'd be interested to know if there exists an MFC control similar to the Qt QTableWidget that can have other widgets nested in each cell.
Not difficult to find on the web..
Resizable layouts:
http://www.codeproject.com/KB/dialog/WndResizer.aspx
Not sure on the grid control with widgets in it, maybe this will do it with some modifications:
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx
As far as I know, there is no layout managers in MFC. A big lack indeed...

Qt 4.6 - How to drag and drop into a QGraphicsView in QtCreator?

I've been trying to figure out how to drag and drop an image into a QGraphicsView using Qt and the QtCreator IDE.
I have read the documentation here: http://doc.trolltech.com/4.6/qgraphicsscene.html#dragEnterEvent
This documentation is too general for me to understand. Can anyone give me an example that works?
I also found a post about the same thing on StackOverflow here: Implementing drag and drop with QT 4.5 using QT Creator environment
I figured out where this 'Promote' function is but I am still confused on how exactly I "promote" this QGraphicsView to drag and drop.
Any help would be greatly appreciated. Thanks in advance!
DragAndDrop:
DragEnterEvent is to be overridden (in code) on a QWidget of your choice. Look at some basic code examples in QtAssistant on how to drag and drop. QGraphicsView is a type-of QWidget.
Promotions:
Lets say you designed a class X that inherits from QGraphicsView. While you are in QtCreator, you can add a QGraphicsView to your widget/form, and then use the promote system to basically do this: "when you see a QGraphicsView here, replace it with the class I'm going to provide". When you look at Object Inspector view in QtCreator or QtDesigner, you should see your class instead of more generic QGraphicsView. (when you promote it)
Hope this helps,