I have attempted to create a round QPushButton using Styles, however it is still coming out rectangular. Could someone point out where I am going wrong please?
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class RoundPushbutton;
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
private:
RoundPushbutton *roundButton;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class RoundPushbutton;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
private:
RoundPushbutton *roundButton;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "roundpushbutton.h"
#include <QVBoxLayout>
#include <QPushButton>
{
vlay->addWidget(btn1);
vlay->addWidget(btn2);
RoundPushbutton *roundButton = new RoundPushbutton();
vlay->addWidget(roundButton);
window->setLayout(vlay);
setCentralWidget(window);
}
#include "mainwindow.h"
#include "roundpushbutton.h"
#include <QVBoxLayout>
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QWidget *window = new QWidget(this);
QVBoxLayout *vlay = new QVBoxLayout(window);
QPushButton *btn1 = new QPushButton("1");
vlay->addWidget(btn1);
QPushButton *btn2 = new QPushButton("2");
vlay->addWidget(btn2);
RoundPushbutton *roundButton = new RoundPushbutton();
vlay->addWidget(roundButton);
window->setLayout(vlay);
setCentralWidget(window);
}
To copy to clipboard, switch view to plain text mode
#ifndef ROUNDPUSHBUTTON_H
#define ROUNDPUSHBUTTON_H
#include <QPushButton>
{
public:
explicit RoundPushbutton
(QWidget *parent
= 0);
};
#endif // ROUNDPUSHBUTTON_H
#ifndef ROUNDPUSHBUTTON_H
#define ROUNDPUSHBUTTON_H
#include <QPushButton>
class RoundPushbutton : public QPushButton
{
public:
explicit RoundPushbutton(QWidget *parent = 0);
};
#endif // ROUNDPUSHBUTTON_H
To copy to clipboard, switch view to plain text mode
#include "roundpushbutton.h"
#include <QPushButton>
RoundPushbutton
::RoundPushbutton(QWidget *parent
){
//button->setGeometry(QRect(100, 100, 300, 300));
button->setText("Quit");
button->setFlat(true);
button->setAttribute(Qt::WA_TranslucentBackground);
button->setStyleSheet(
"background-color: red;"
"border: 1px solid black;" //outline
"border-radius: 150px;" //corners
"color: lightGray; " //text
"font-size: 35px;"
);
}
#include "roundpushbutton.h"
#include <QPushButton>
RoundPushbutton::RoundPushbutton(QWidget *parent)
: QPushButton(parent)
{
QPushButton *button = new QPushButton();
//button->setGeometry(QRect(100, 100, 300, 300));
button->setText("Quit");
button->setFlat(true);
button->setAttribute(Qt::WA_TranslucentBackground);
button->setStyleSheet(
"background-color: red;"
"border: 1px solid black;" //outline
"border-radius: 150px;" //corners
"color: lightGray; " //text
"font-size: 35px;"
);
}
To copy to clipboard, switch view to plain text mode
Instead of 2 normal QPushbuttons followed by a round one, they all look normal.
Thank you.
Bookmarks