Solved Regarding the mirror effect required for text in QLabel
-
@Pradeep-Kumar
Not seeing the image / link? -
Wouldn't be easier to inherit from QLabel and override set text function. In that way, you can do custom processing for it.
-
This post is deleted! -
-
My solution would be overriding paintEvent of QLabel. You have to rotate text. It is a bit hard but you can start from qt source code to check default implementation of paintEvent and make a small change to rotate it. After that you can have another widget one with normal label big font, other with small font rotated text, put them into a layout and present to user. Or, if you can do all this in a label paintEvent.
http://stackoverflow.com/questions/26511409/qt-creator-rotate-a-qlabel-that-contains-text-90-degrees
-
I will give it a try guys. Will update.
-
Thanks!
I noted as well, I will try when I have time. In case I come up with a good looking widget, I will share with you guys.
-
Hi
The hard part is most likely to get good looking reflection.
Some gradient and transparency will help but will take some playing around to look
nice. :) -
Hi! Maybe a bit over-engineered, but I'd use a custom QGraphicsEffect for this. The wiki article Text Shadows in QLabel shows how to apply it.
-
Guys with your help i have compiled the following code.
I have used 2 classes
Follow is the link where the code will be available.By clicking QPushButton , i am showing QLabel.
classes i have used
LabelShadowEffect.h
LabelShadowEffect.cpphttp://codepaste.net/dke2fr
http://codepaste.net/jec1hmand i have used LabelRotation Class where i have inherited from QLabel .
http://codepaste.net/gdvi11
http://codepaste.net/tqo8bnGuys help me with the code where i require the alphabets to be reflected, but in the output, it is not.
Below is the link of the output
https://postimg.org/image/v13g6x943/
Guidance is required.
-
For the LabelRotation, I guess you should use righttoleft direction, then it will be how you want.
layoutDirection : Qt::LayoutDirection
This property holds the layout direction for this widget.
By default, this property is set to Qt::LeftToRight. -
I used below line but still didnt work
painter.setLayoutDirection(Qt::RightToLeft);
can u share the piece of code or edit in the code which i provided in the link. I will also try to make it work.
-
Here is an example using
QGraphicsEffect
. The result looks like this:mainwindow.cpp
//... #include "myeffect.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); MyEffect *effect = new MyEffect(this); ui->label->setGraphicsEffect(effect); } //...
myeffect.h
#ifndef MYEFFECT_H #define MYEFFECT_H #include <QGraphicsEffect> class MyEffect : public QGraphicsEffect { Q_OBJECT public: MyEffect(QObject *parent = Q_NULLPTR); virtual QRectF boundingRectFor(const QRectF &sourceRect) const override; virtual void draw(QPainter *painter) override; }; #endif // MYEFFECT_H
myeffect.cpp
#include "myeffect.h" #include <QPainter> #include <QPixmap> #include <QPoint> #include <QSize> MyEffect::MyEffect(QObject *parent) : QGraphicsEffect(parent) { } QRectF MyEffect::boundingRectFor(const QRectF &sourceRect) const { return sourceRect.adjusted(0, 0, 0, sourceRect.height()); } void MyEffect::draw(QPainter *painter) { painter->save(); QPoint offset; const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset); painter->drawPixmap(offset, pixmap); QImage img = pixmap.toImage(); const QSize s = img.size(); const qreal fac = 255.0 / s.height(); const qreal brightness = 0.9; for (int i=0; i<s.width(); ++i) { for (int j=0; j<s.height(); ++j) { QRgb argb = img.pixel(i,j); int grayValue = (255-(fac*j))*brightness; grayValue = grayValue < 0 ? 0 : grayValue; grayValue = grayValue > 255 ? 255 : grayValue; QColor newColor(grayValue, grayValue, grayValue, qAlpha(argb)); img.setPixelColor(i,j,newColor); } } img = img.mirrored(); painter->drawImage(0,0, img); painter->restore(); }
Hope it helps!
-
Thanks man
I got the output , here is the link of the output which got.https://postimg.org/image/qtwp1ywst/
Thanks,
-
Thanks guys @muratkarakus7 @mrjj @Wieland for your support, marking as solved, which will be useful.
Thanks.