Qt - QScrollBar skinning issue - c++

I'm trying to skin a QScrollBar by reimplementing the paintEvent function, but I'm having trouble. I can't find any information on the buttons on the scroll bar, and I can only find (limited) information on the actual slider (the handle you can grab and drag). I looked at the QStyle as well and it still only gives information on the scroll handle and not the buttons. Hardcoding or using magic numbers is not an option because the buttons are placed differently on different operating systems (see: Here). Is there any way to programmatically get the layout of the Scrollbar, so I could accurately render the buttons and scroll handle at their correct positions?

As the painting itself is done by underlying style, not QScrollBar itself I'd suggest following:
Use QProxyStyle to override painting of QScrollBar.
This is how does Qt paints QScrollBar. You can alternate that
As alternative I'd suggest using Qt Style Sheets to change QScrollBar look'n'feel

Related

How to draw a caret/arrow bottom of a QDialog on qt5

I want to draw a caret / arrow top or bottom of a qt window. I cannot find any document regarding to this.
How can I accomplish this task with qt5? I've searched all possible words but can't find anything.
Can this be applied to QDialog or qml needed? My first choice is QDialog since I have a webengine and other qwidgets already in a QDialog.
I'm using C++.
Here is what I mean:
Most window-managers don't support non-rectangular windows directly, which means that if you want to do something like this you'll need to fake it by making the window large enough to include both its normal content and the desired caret-shape inside the window-area, and making the window transparent at the top.
To do that, call setAttribute(Qt::WA_TranslucentBackground) and setAttribute(Qt::WA_FramelessWindowHint) on your dialog, and override paintEvent(QPaintEvent *) to paint the dialog's background only for the parts of the dialog you want to be non-transparent.

Suggestion wanted for MFC custom scrollbars

I want to make my own scrollbars for a custom drawn plot, like this image, what would be the best way to go?
Scrollbars should:
Only be visible when mouse hover over it (with fade in/out)
Be a part of the x/y axis of the plot, like in the picture
Not have any arrow buttons, just the thumb Thinner than the normal scrollbars
Would you suggest to:
Create everything from scratch, handling paging, scrollwheel etc.
Try to inherit CScrollBar and do my own drawing?
From what I've read, it's not very easy to customize scrollbars in MFC, for example here)
First off, these have to be scrollbar (or other) controls, not window scrollbars (used for scrolling a window).
Second, the statement "it's not very easy to customize scrollbars in MFC", is only partially true. MFC is a "thin wrapper" of Windows API, so you should better refer to the documentation of the Windows scrollbar control.
Then there is the CScrollBar class, but took a short look, and indeed, it does not really offer anything more than the Windows scrollbar does. As for the sample in the link you posted is a new (custom) control (painting everything on its own), i.e. literally "from scratch", not inheriting anything from CScrollBar.
So, you have to look into the Windows scrollbar control, and what it offers. Did take a look, and saw few things. Unfortunately there seems to be no owner-draw functionality. You can process the WM_CTLCOLORSCROLLBAR message, but this only allows you to change colors.
And according to the documentation the background color only. This appears to be the only possible customization, apart from the SBM_ENABLE_ARROWS message, which can hide the arrows. And no fading effect. If these are enough to you, you could try the Windows/MFC scrollbar, otherwise try writing your own.

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.

Qt: scrolling complex content. Web-Browser engine. Selecting a text

Just curious about scrolling complicated content inside web browser - like application. Lets assume i am using Qt and C++. This is not "how to" question, but more like "how does it work"? Completely derived from my curiosity irrational questions.
I did small experiment.
Created large QWidget 800x60000 px.
Added 300 QWidgets 800x200 px that are painting themselves using QPainter. Each widget prints its unique name to console when paintEvent() is called.
Added (1.) to a QScrollArea 800x800.
When scrolling, i notice redrawing only widgets that are not fully displayed on the screen. It is only 1 widget at a time (scene: http://savepic.ru/2670640.jpg).
So QScrollArea (or QWidget? Who deside what widget to repaint?) is smart - we do not have CPU loaded redrawing all the 300 widgets all the time or memory consumption storing 800x60000 pixmap (-;
Lets assume i want to use mouse to select text and other elements on my "webpage". So i want to be able to mark them (by changing background). How would i implement that? How different web browsers do that? Selecting pictures, text, tables... Should i think about tracking the mouse and drawing gray/blue/pink background boxes behind elements and my custom widgets?
I have another experiment - displaying stack of messages. The scheme is the same, except QPainter is not used here - only QLabels, QTextExits, QPushButtons (scene: http://savepic.ru/2632728.jpg). I can set a flag SelectableByMouse for QLabel, but how do i select more than 1 message?
You could suggest me to use some Qt HTML renderer, but this is not the answer for 'how does it work".

Qt: Dragging a widget to scroll the widget's parent QScrollArea?

I've got a long horizontal QLabel displaying a png (the image shows a signal/time graph). Under that, I've got a QTableWidget. Both of these are in a QScrollArea because I want them to stay vertically aligned (the cells in the table correspond with the signal seen directly above them). I'm trying to add a handler to the QLabel such that the user can use the picture itself to scroll the scrollarea, rather than having to use the scrollbar. Is there a tried-and-tested way to do this? Directly setting the scrollarea's sliderPosition inside the QLabel's dragMoveEvent doesn't seem smart, because when the scrollarea scrolls it also leads to another dragMoveEvent on the (moving) QLabel.
I would suggest wrapping the combination (including the scroll area) in their own widget, and overriding the dragMoveEvent() on that widget. The dragMoveEvent() shouldn't be triggered when you change the scroll position if you are doing it this way, I wouldn't think, although I haven't actually tested it.