in my application there is the QProgressBar I use, but it's not quite illustrating progress of a process, rather it represents a state. Therefore, I want it not to animate on Mac, as it always does. I have no experience with Cocoa, but Qt does not allow me to do that. And therefore I ask some more experienced Cocoa programmers: is it even possible to stop the progress bar animation? I looked for that for quite a while, but I didn't find anything.
Thank you in advance.
You could either call setStyle() on the QProgressBar to use a different kind of QStyle instead (i.e. one that doesn't animate); or you could ditch the QProgressBar altogether and use a different widget type entirely (e.g. a QLabel, or just subclass QWidget and implement paintEvent() do draw whatever you want the widget to look like)
Related
I'm trying to do an application with the Qt framework. My main problem with this framework is the design. I made a lot of research and I find two ways to achieve the style of my app.
Qt StyleSheet
Qt Style class
I find a lot of people talking about the QtStyleSheet but almost nothing on QStyle.
What's the best solution ? Have you examples with QStyle ?
I'm trying to programming a QStyle class but I find it too complex. The Qt documentation it's not enough for me to understand all the topic.
Here is a snippet of my code to do a Transparent PushButton with a special Font and a margin. (code in a drawControl function of my QProxyStyle class)
// draw background
QRect button_rect = button_option->rect;
// draw background
button_rect.adjust(12, 12, -12, -12);
painter->fillRect(button_rect, QColorConstants::Transparent);
painter->setPen(QColorConstants::Black);
// define the font
QFont font("Material Icons");
font.setPixelSize(24);
painter->setFont(font);
// draw text
painter->drawText(button_rect, Qt::AlignCenter, button_option->text);
QStyleSheet is like a CSS (but here we call it QSS). With QStyle and overriding events, you have more flexibility. , if you'd like to have so much flexibility, you can use QStyle + overriding events and more helper classes like QPainter, etc.
but if you'd like to have some magic changes with a few lines, I suggest that you use QSS.
I do not exactly know what is your question. But yes, you are right that overriding QStyle is very complex and is not well documented. If you want to make your own QStyle, then painting buttons is probably the most simple thing you will encounter. Drawing more complex widgets such as combo boxes scrollable things, tabs, etc. might be a nightmare. If you want to have a look at an example of quite nicely overriden QStyle, have a look here https://github.com/randrew/phantomstyle
Using stylesheets is much simpler but it also has several drawbacks and rendering is much slower than without stylesheets.
So I cannot provide any concrete advice. The decision will be up to you and up to your requirements.
Premise: I need to change the colors of the default CScrollBar defined in MFC (thumb + track + arrows), but after doing some research I realized that this isn't exactly an easy task.
Question: would it be better if I tried to draw OVER the existing scrollbar, or should I create a new scrollbar control from scratch?
If I limited myself to drawing on it, I would have the advantage of not having to manage all the messages that deal with the other features of the scrollbar (in addition to the drawing), but it is VERY complicated to find all the points where windows redraws the bar, since the scrollbar is not redrawn only in the OnPaint() method.
If I redo it from scratch, I would no longer have the problem of identifying all the points where the bar is redrawn ... but on the other hand I should reimplement all the scrollbar features from scratch.
I've already looked at this link:
https://www.codeproject.com/Articles/14724/Replace-a-Window-s-Internal-Scrollbar-with-a-custo
but the proposed method does not seem to work for newer versions of Windows (from Vista onwards).
Any advice is appreciated, thanks in advance.
We had exactly the same problem and your attempt to overdraw the original scrollbar was what we tried first. We dropped that attempt again due to some issues, which I don't remember in detail (not receiving all mouse or draw messages, flickering, ...). Our solution was some effort, but works now:
We implemented first a class CCustomScrollBar, which is NOT derived from CScrollBar, because the CScrollBar is just a wrapper around the Windows implementation and overwriting OnPaint() doesn't work perfect. And yes, all things must be implemented from scratch.
Second we implemented a template class CWndCustomScrollBar keeping two CCustomScrollBars and managing all around them as a standard window would do with its embedded scrollbars. The free client area then can be achieved via a method GetClientRectWithoutScrollBar() to work similar as a standard window would do.
I'm looking to make a sprite animation editor. I have the loading of my custom animation file done but now need to get the actual ui started. I'm really just stuck on what widgets I would use to actually play my animation. I need to be able to go to certain frame, play, pause, loop, etc. Once I'm done with the viewing portion I plan on adding in the editing.
I've seen AnimatedSprite in qt docs but that seems to only allow playback of sprites in the same file. In my situation sprites can be from multiple image files and sometimes doesn't follow a grid like sprite cutter.
First of all, you should decide whether you want to use QML or Widgets. AnimatedSprite is QML related class. All widget-related classes starts with "Q" letter.
If you decide to use Qt Widgets, I would recommend to take a look at Qt Animation Framework in combination with Qt Graphics View Framework. Most likely it will not let you do everything you want out of box, but it should provide you with a rich set of useful tools.
If you need here are some examples.
Hope it helps.
Have a look at QMovie. This class may provide all the methods you need, as long as you only want to use it for viewing. The QMovie can be passed to a QLabel to show the animation.
QMovie however supports only gif out of the box (and there is a third party plugin for apng files). You would probably have to create your own image handle plugin to support your format.
If thats not applicable or to complicated, you will most likely have to create your own custom widget. Have a look at the painter example. Playing an animation is not that hard if you have all the frames. A simple QTimer to change the image to be drawn in a constant rate should work.
I want to create a slider which contain a different slider handle and i want to paint it according to slider handle position in the slider.
You could use QProxyStyle to ovrride drawComplexControl method - you will have to draw entire control on your own, as there is no separate flags in QStyle::ControlElement for parts of QSlider.
maybe you should look at this: http://doc.qt.io/qt-4.8/stylesheet-examples.html#customizing-qslider
If I understand you correctly, you want a slider that changes not only its position but also its appearance as you slide, right? For example, a mix of QDial and QSlider, ie. a slider with a turning knob.
If so, you will need to subclass either QSlider or QAbstractSlider (or QDial) and do the painting in your own paintEvent(). Note, however, that you will loose all style-awareness unless you care about that yourself (and that is an interesting topic in itself, see http://doc.qt.io/qt-4.8/style-reference.html for more info).
The Qt demos and examples, or the QSlider/QDial source code itself may serve as examples on how to overload a paintEvent().
I want to show a car's path in a window in real time, how to do that, and what classes I have to use. Is there anything like drawing area, in Qt.
Any Help will be appreciated.
You'll need to read up on QGraphicsview. There are several helpful examples that show every bit of what functionality is present here. The implementation itself... I guess it's just a bunch of QLines on a QGraphicsScene. The realtime part is handled by calling repaint or paintevent or whatever it's called periodically, or setting up a complex animation.
The Qwt library on top of Qt is pretty good for this.