Question

I'm new to QT. I used following code to add a button in to a QGraphicScene

QGraphicsScene* scene = new QGraphicsScene;

QPushButton *btnuser = new QPushButton();

btnuser->resize(32, 32);
btnuser->setGeometry(QRect(QPoint(50, 50),QSize(32, 32)));

btnuser->setText("1");
btnuser->setAccessibleName("1");
connect(btnuser, SIGNAL( clicked() ), this, SLOT( on_btnProcess_clicked() ) );

scene->addWidget(btnuser);

But in the output there is a rectangle behind the button. How can I remove that?

Was it helpful?

Solution

I solved this problem by setting minimum width and height.

QPushButton *btnuser = new QPushButton();
btnuser->setMinimumHeight(20);
btnuser->setMinimumWidth(20);

Then I set the same width and height for the button in setGeometry method

btnuser->setGeometry(QRect(QPoint(pointx,pointy),QSize(20, 20)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top