How do I subclass QDial to show notches values ?
-
-
Hi
What about just placing a label next to the dial (or on top of it)
hook up the void valueChanged(int value)
to a slot in main
and then simple change the text in the label when dial is changed? -
Hi
Your English is fine but its not clear how this Dial should look likeSo INSTEAD of values/small ticks on the Dial, you want text `?
So first little tick is Hello etc ? -
Hi
Your English is fine but its not clear how this Dial should look likeSo INSTEAD of values/small ticks on the Dial, you want text `?
So first little tick is Hello etc ? -
@mrjj
Something like that :
Gyazo Link -
@Punt
Ok
You can sublass it and override the paintEvent
make it paint as normal, and then paint the text on top.
But you show 4 texts, do you have more for real app? -
Hi
Well then subclass will work best as you can add support
for having a list of TickTexts or what u call them :) -
@Punt
Ok
You can sublass it and override the paintEvent
make it paint as normal, and then paint the text on top.
But you show 4 texts, do you have more for real app?@mrjj said:
@Punt
Ok
You can sublass it and override the paintEvent
make it paint as normal, and then paint the text on top.
But you show 4 texts, do you have more for real app?I know how to subclass & override, but "make it paint as normal and then paint the text", I don't have any idea how to do it ...
-
@mrjj said:
@Punt
Ok
You can sublass it and override the paintEvent
make it paint as normal, and then paint the text on top.
But you show 4 texts, do you have more for real app?I know how to subclass & override, but "make it paint as normal and then paint the text", I don't have any idea how to do it ...
-
@Punt
Oh sorry being unclear
When you have overridden paint
in top you call the base class
void mycooldial::paintEvent( ..
QDial::PaintEvent(event); << call the normal paintthen after u paint text on top of it.
@mrjj
OK here I am :.h :
#ifndef CUSTOMDIAL_H #define CUSTOMDIAL_H #include <QObject> #include <QDial> class CustomDial : public QDial { Q_OBJECT public: CustomDial(QWidget * parent = nullptr, double knobRadius = 5, double knobMargin = 5); private: virtual void paintEvent(QPaintEvent*pe) override; }; #endif // CUSTOMDIAL_H
.cpp :
#include "customdial.h" CustomDial::CustomDial(QWidget* parent, double knobRadius, double knobMargin) : QDial(parent) { // Default range QDial::setRange(0,100); } void CustomDial::paintEvent(QPaintEvent* pe) { QDial::paintEvent(pe); }
It seems to work, I have my QDial then I'll try to add my text...
But I have :
QMetaObject::connectSlotsByName: No matching signal for on_pushButton_pressed() QMetaObject::connectSlotsByName: No matching signal for on_pushButton_clicked() QMetaObject::connectSlotsByName: No matching signal for on_pushButton_released() QMetaObject::connectSlotsByName: No matching signal for on_dial_valueChanged(int)
-
Hmm
you dont show any connect statements?So this from other part of project.
This might happen if you add slot by right clicking in Creator and then later rename slot or the button/widget
Its not related to the subclass as such. -
Hmm
you dont show any connect statements?So this from other part of project.
This might happen if you add slot by right clicking in Creator and then later rename slot or the button/widget
Its not related to the subclass as such. -
@mrjj
Oh sorry my bad to disturb you for this..
This is SLOT that I used earlier to try things with QDial --'Ok I'll try to paint my text now :)
-
Ok, I understand how it works.. I have an idea to determinate the position of my texts (unit cercle I guess).
But I have a problem, because for example (with a QDial 100x100) :
- if I add text in (0,50) a part of the text will be on the QDial..
- if I add text in (-10,50), a part of the text will be cut
I guess I have to extend the painting zone.. but I don't find anything...
-
Ok, I understand how it works.. I have an idea to determinate the position of my texts (unit cercle I guess).
But I have a problem, because for example (with a QDial 100x100) :
- if I add text in (0,50) a part of the text will be on the QDial..
- if I add text in (-10,50), a part of the text will be cut
I guess I have to extend the painting zone.. but I don't find anything...
-
@Punt
Hi the
"Painting zone" is the size of the QDial
You cannot paint outside it using -100 for x
It clip clip as you saw.
You cannot increase this area unless its ok the QDial also becomes bigger. -
@mrjj
Maybe I can reduce the QDial then ? Like the radius of the circle ?Or last idea : I create a new class, in which I put an "aera" like a Widget (?), I add a QDial and I draw my "notches-text-values" (Still don't know how to call it xDD)
@Punt
well maybe. i dont think so.
I think it uses all its area.
else u need to copy the paint function and alter it to allow
to paint smaller than the area.
You should look in source and see what it uses to better understand it. -
sorry I miss last part.
Yes also option to make a composite class where u have QDial in center ( in a layout) and
let ur class paint on top of it all. -
sorry I miss last part.
Yes also option to make a composite class where u have QDial in center ( in a layout) and
let ur class paint on top of it all.