PDA

View Full Version : QMainWindow with Partial Transparent Background and Custom Shape



rmagro
24th May 2012, 08:54
Hi Qt developers,

I wrote a simple Qt4 code to get a QMainWindow with Partial Transparent Background and Custom Shape..
Here the core of my application:



setMask((new QPixmap("logoic_big.png"))->mask());

QPalette* palette = new QPalette();
palette->setBrush(QPalette::Background,*(new QBrush(*(new QPixmap("logoic_big.png")))));
setPalette(*palette);

setWindowFlags(Qt::FramelessWindowHint);
QWidget *centralWidget = new QWidget(this);
QGridLayout *layout = new QGridLayout();

centralWidget->setLayout(layout);

QPushButton* m_showAddCommentButton = new QPushButton();
m_showAddCommentButton->setFlat(true);
m_showAddCommentButton->setAutoFillBackground(true);
m_showAddCommentButton->setFixedSize(40,40);
QPalette palett = m_showAddCommentButton->palette();
palett.setColor(QPalette::Button,QColor(Qt::transp arent));
m_showAddCommentButton->setPalette(palett);
m_showAddCommentButton->setIcon(QIcon("exit.png"));
m_showAddCommentButton->setIconSize(QSize(40,40));
m_showAddCommentButton->setToolTip("Close");

layout->addWidget(m_showAddCommentButton,0,0);

setCentralWidget(centralWidget);

connect(m_showAddCommentButton, SIGNAL(clicked()), this, SLOT(close()));


My question is:
How can I put buttons in a specified positon, that I like, of my custom shape QmainWindows ?

Many thanks in advance..
roby

Spitfire
25th May 2012, 16:00
Don't use layout, then you can move button where you want:



QPushButton* pb = new QPushButton( "Test Button", centralWidget );
pb->move( 200, 155 );