Making a Round-Shaped QPushButton

Summary : This code shows how to make a Round-Shaped QPushButton.
 Qt Version:  4.7.4
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QRegion>

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	QMainWindow *window = new QMainWindow();  
    
        window->setWindowTitle(QString::fromUtf8("Round-Shaped QPushButton"));
        window->resize(300, 250);
	
        QWidget *centralWidget = new QWidget(window);
	
	QPushButton* button = new QPushButton(centralWidget);
	button->setText("Button 1");
	button->setFixedHeight(200);
	button->setFixedWidth(200);
	
	//Set Starting point of region 5 pixels inside , make region width & height
	//values same and less than button size so that we obtain a pure-round shape
	QRegion* region = new QRegion(*(new QRect(button->x()+5,button->y()+5,190,190)),QRegion::Ellipse);
	button->setMask(*region);	
	
	window->setCentralWidget(centralWidget);
	window->show();
	
	return app.exec();

}
Output :
Round-Shaped QPushButton


Similar Examples
Adding Click Event to QPushbutton
Creating Toggle QPushButton Example
Changing QPushButton Text Color
QPushButton Mouse Over Animation Using QTimer
Change QPushButton Background Color
Setting QPushButton Background Image

Examples About Some Qt Classes
QLcdNumberQTimer
QPushButtonQMessageBox
QTabWidgetQtConcurrent
QLabelQList
QKeyEventQSlider
QFontDialogQSpinBox
QTableWidgetQTextBrowser
Qt StylesheetsQCheckBox
QComboBoxQCloseEvent
QProgressBarQProgressDialog
QTreeWidgetQSignalMapper



Recommend This : Bookmark and Share
 
Want any example ? Feel free to tell us:
(Max. 2000 characters)
Please note that we do not guarantee to respond.Thanks.

C++
OpenSceneGraph
Fundamentals
QT
Boost
wxWidgets
Java
Python



Copyright 2011 - 2013 | All Rights Reserved
All trademarks are properties of their respective owners.
Contact| Privacy Policy| About Us