效果图如下:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QRadioButton>
#include <QHBoxLayout>
#include <QCheckBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStyle::StandardPixmap a[] ={
QStyle::SP_TitleBarMenuButton,
QStyle::SP_TitleBarMinButton,
QStyle::SP_TitleBarMaxButton,
QStyle::SP_TitleBarCloseButton,
QStyle::SP_TitleBarNormalButton,
QStyle::SP_TitleBarShadeButton,
QStyle::SP_TitleBarUnshadeButton,
QStyle::SP_TitleBarContextHelpButton,
QStyle::SP_DockWidgetCloseButton,
QStyle::SP_MessageBoxInformation,
QStyle::SP_MessageBoxWarning,
QStyle::SP_MessageBoxCritical,
QStyle::SP_MessageBoxQuestion,
QStyle::SP_DesktopIcon,
QStyle::SP_TrashIcon,
QStyle::SP_ComputerIcon,
QStyle::SP_DriveFDIcon,
QStyle::SP_DriveHDIcon,
QStyle::SP_DriveCDIcon,
QStyle::SP_DriveDVDIcon,
QStyle::SP_DriveNetIcon,
QStyle::SP_DirOpenIcon,
QStyle::SP_DirClosedIcon,
QStyle::SP_DirLinkIcon,
QStyle::SP_DirLinkOpenIcon,
QStyle::SP_FileIcon,
QStyle::SP_FileLinkIcon,
QStyle::SP_ToolBarHorizontalExtensionButton,
QStyle::SP_ToolBarVerticalExtensionButton,
QStyle::SP_FileDialogStart,
QStyle::SP_FileDialogEnd,
QStyle::SP_FileDialogToParent,
QStyle::SP_FileDialogNewFolder,
QStyle::SP_FileDialogDetailedView,
QStyle::SP_FileDialogInfoView,
QStyle::SP_FileDialogContentsView,
QStyle::SP_FileDialogListView,
QStyle::SP_FileDialogBack,
QStyle::SP_DirIcon,
QStyle::SP_DialogOkButton,
QStyle::SP_DialogCancelButton,
QStyle::SP_DialogHelpButton,
QStyle::SP_DialogOpenButton,
QStyle::SP_DialogSaveButton,
QStyle::SP_DialogCloseButton,
QStyle::SP_DialogApplyButton,
QStyle::SP_DialogResetButton,
QStyle::SP_DialogDiscardButton,
QStyle::SP_DialogYesButton,
QStyle::SP_DialogNoButton,
QStyle::SP_ArrowUp,
QStyle::SP_ArrowDown,
QStyle::SP_ArrowLeft,
QStyle::SP_ArrowRight,
QStyle::SP_ArrowBack,
QStyle::SP_ArrowForward,
QStyle::SP_DirHomeIcon,
QStyle::SP_CommandLink,
QStyle::SP_VistaShield,
QStyle::SP_BrowserReload,
QStyle::SP_BrowserStop,
QStyle::SP_MediaPlay,
QStyle::SP_MediaStop,
QStyle::SP_MediaPause,
QStyle::SP_MediaSkipForward,
QStyle::SP_MediaSkipBackward,
QStyle::SP_MediaSeekForward,
QStyle::SP_MediaSeekBackward,
QStyle::SP_MediaVolume,
QStyle::SP_MediaVolumeMuted,
QStyle::SP_LineEditClearButton};
const int nPerColCount = 6;
auto nIconCount = sizeof a / sizeof a[0];
QWidget *w = new QWidget(this);
w->setGeometry(0,0,this->width(), this->height());
QGridLayout *layout = new QGridLayout(w);
for (auto nIconIndex = 0; nIconIndex < nIconCount; ++nIconIndex)
{
QPushButton* pBtn = new QPushButton();
auto icon = this->style()->standardIcon(a[nIconIndex]);
pBtn->setIcon(icon);
int nColIndex = nIconIndex % nPerColCount;
int nRowInex = nIconIndex / nPerColCount;
layout->addWidget(pBtn, nRowInex, nColIndex);
}
}
MainWindow::~MainWindow()
{
delete ui;
}