Results 1 to 2 of 2

Thread: QMainWindow with Partial Transparent Background and Custom Shape

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QMainWindow with Partial Transparent Background and Custom Shape

    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:

    Qt Code:
    1. setMask((new QPixmap("logoic_big.png"))->mask());
    2.  
    3. QPalette* palette = new QPalette();
    4. palette->setBrush(QPalette::Background,*(new QBrush(*(new QPixmap("logoic_big.png")))));
    5. setPalette(*palette);
    6.  
    7. setWindowFlags(Qt::FramelessWindowHint);
    8. QWidget *centralWidget = new QWidget(this);
    9. QGridLayout *layout = new QGridLayout();
    10.  
    11. centralWidget->setLayout(layout);
    12.  
    13. QPushButton* m_showAddCommentButton = new QPushButton();
    14. m_showAddCommentButton->setFlat(true);
    15. m_showAddCommentButton->setAutoFillBackground(true);
    16. m_showAddCommentButton->setFixedSize(40,40);
    17. QPalette palett = m_showAddCommentButton->palette();
    18. palett.setColor(QPalette::Button,QColor(Qt::transparent));
    19. m_showAddCommentButton->setPalette(palett);
    20. m_showAddCommentButton->setIcon(QIcon("exit.png"));
    21. m_showAddCommentButton->setIconSize(QSize(40,40));
    22. m_showAddCommentButton->setToolTip("Close");
    23.  
    24. layout->addWidget(m_showAddCommentButton,0,0);
    25.  
    26. setCentralWidget(centralWidget);
    27.  
    28. connect(m_showAddCommentButton, SIGNAL(clicked()), this, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMainWindow with Partial Transparent Background and Custom Shape

    Don't use layout, then you can move button where you want:

    Qt Code:
    1. QPushButton* pb = new QPushButton( "Test Button", centralWidget );
    2. pb->move( 200, 155 );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. how to mask my x::widget to the background of a shape
    By saman_artorious in forum Newbie
    Replies: 1
    Last Post: 27th February 2012, 10:25
  2. Replies: 3
    Last Post: 13th November 2011, 08:12
  3. set transparent background for custom widget is not effective
    By kongkong163 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 1st March 2011, 01:36
  4. Custom QRubberBand with transparent background
    By mdomke in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2010, 10:34
  5. Transparent background on QLabel on transparent QWidget
    By codeslicer in forum Qt Programming
    Replies: 1
    Last Post: 13th February 2008, 02:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.