Reputation: 14053
Hi I need to create prototype tool for smartphone screen using Qt, I have png image of the smartphone right now and need to do place some text and image as shown in below image.
So my question is, is there anything similar already exist to create such a tool in C++ Qt.
Or do I need to use QPainter for achieving it.
Or any better method to accomplish it.
Upvotes: 0
Views: 40
Reputation: 4010
I can give you small code example how you can create such app. For main window you can set brush, created from this image, then set mask for window to ensure it painting right way. Also you need set Qt::FramelessWindowHint flag. Then you can add all needed widgets to this widget. Small example (assuming :/img/i.png
is your picture, saved to resources):
At .h
file:
#include <QFrame>
#include <QPixmap>
class TestFrame : public QFrame
{
Q_OBJECT
public:
TestFrame(QWidget* p = 0);
protected:
void resizeEvent(QResizeEvent* e) override;
private:
QPixmap _pix;
};
At .cpp
file:
#include <QBitmap>
TestFrame::TestFrame(QWidget *p) :
QFrame(p, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint),
_pix(":/img/i.png")
{
QPalette pal = palette();
pal.setBrush(QPalette::Background, QBrush(_pix));
setPalette(pal);
resize(_pix.width(), _pix.height());
}
void TestFrame::resizeEvent(QResizeEvent *e)
{
QFrame::resizeEvent(e);
setMask(_pix.scaled(size()).mask());
}
Also make sure your image has alpha-channel for invisible parts (I mean corners). For now it hasn't.
Upvotes: 1