Results 1 to 19 of 19

Thread: How any widget/frame/button to be displayed/look like outside boundary of main window

  1. #1
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default How any widget/frame/button to be displayed/look like outside boundary of main window

    Hi

    Please see the attached screenshots of software clean my Mac(Dummy-min.jpg)
    I have to create same screen for my application.
    This window contains two specific widget - one vertical frame containing a lot of options - showing outside the boundary of main window.
    second Scan button is showing outside the boundary of main window.

    Please help me or guide me that how we can create like this type of windows.
    I am using Qt 5.14 for MacOS.

    Please reply.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    I think you could create these as top-level, frameless widgets (or non-modal dialogs) and use the Qt::FramelessWindowHint and Qt::WindowStaysOnTopHint window flags. (i.e. created with no parent) The widget containing the button might need a transparent background. If these windows have to stay in the same position relative to the main window, then you'll have to implement QEvent-handling code in the main window code for move, resize, hide, show, close, and maybe some other events to move / hide / close these other windows along with the main window.

    Since they have no parent, you will have to explicitly call deleteLater() when the main window is destroyed, I think. This should probably be done in a main window slot connected to the QObject::destroyed() signal for the main window. If you do it in the main window destructor instead, I think that will be too late and could cause a crash.
    Last edited by d_stranz; 8th November 2022 at 18:06.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by d_stranz View Post
    I think you could create these as top-level, frameless widgets (or non-modal dialogs) and use the Qt::FramelessWindowHint and Qt::WindowStaysOnTopHint window flags. (i.e. created with no parent) The widget containing the button might need a transparent background. If these windows have to stay in the same position relative to the main window, then you'll have to implement QEvent-handling code in the main window code for move, resize, hide, show, close, and maybe some other events to move / hide / close these other windows along with the main window.

    Since they have no parent, you will have to explicitly call deleteLater() when the main window is destroyed, I think. This should probably be done in a main window slot connected to the QObject::destroyed() signal for the main window. If you do it in the main window destructor instead, I think that will be too late and could cause a crash.

    Thanks for reply.
    I am trying to implement as per your guidance. I will get back soon if I face some issue.

    Thanks


    Added after 1 17 minutes:


    Dear Sir

    I have attached sample code on which I am working. I have attached created screen also.
    I have created two widget. One is the Main window which contains Minimize, Maximize and close button and Title bar should be pressed and movable.
    Second screen is the Frame Option and Button and have done the transparent background of second widget. Both Window look like one windows that is excellant but First windows is not clickable and second screen is coming front on first windows.
    Please tell me how first windows should be clickable, title bar should be movable when second windows is showing in front and taking control.

    Please reply What is incorrect method that I am following. please provide the solution.

    Thanks
    Santosh
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by santosh.kumar; 9th November 2022 at 13:08.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    I am not going to write your code for you. When I have time later today, I will look at what you have written already and see if there is anything that seems like a problem and tell you about it.

    Please explain which windows you mean when you say "first window", "second window", and so forth. Is the "first window" the one with the vertical row of buttons and "second window" the one with the round button?

    Edit:

    - You need to create separate windows for your column of buttons and the round button instead of putting them into a combined "CustomSplash" dialog.

    - If you inherit them from QDialog, then they need to be non-modal. Your CustomSplash widget is application modal, so that prevents the main window from getting focus.

    - When you create the window for the column of buttons and the round button, you should set the windows flags WindowStaysOnTopHint and FramelessWindowHint. This will prevent them from moving behind the main window when it has focus.
    Last edited by d_stranz; 9th November 2022 at 23:08. Reason: updated contents
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by d_stranz View Post
    I am not going to write your code for you. When I have time later today, I will look at what you have written already and see if there is anything that seems like a problem and tell you about it.

    Please explain which windows you mean when you say "first window", "second window", and so forth. Is the "first window" the one with the vertical row of buttons and "second window" the one with the round button?

    Edit:

    - You need to create separate windows for your column of buttons and the round button instead of putting them into a combined "CustomSplash" dialog.

    - If you inherit them from QDialog, then they need to be non-modal. Your CustomSplash widget is application modal, so that prevents the main window from getting focus.

    - When you create the window for the column of buttons and the round button, you should set the windows flags WindowStaysOnTopHint and FramelessWindowHint. This will prevent them from moving behind the main window when it has focus.

    Dear Sir
    Thanks for reply. Sir, I am working as per your guidance and as per Edit and I will be back soon if face any issue.

    Thanks
    Santosh

  6. #6
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by santosh.kumar View Post
    Dear Sir
    Thanks for reply. Sir, I am working as per your guidance and as per Edit and I will be back soon if face any issue.

    Thanks
    Santosh
    I am facing issue. I have created separate windows for column of buttons and the round button.
    How to make modeless Qt window on top of our main window, but not on top of other applications.

    Please reply.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Can you post the code that shows how you are creating your windows? It would be best if you eliminated any extra code and just gave an example that builds and runs.
    Last edited by d_stranz; 15th November 2022 at 17:41.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by d_stranz View Post
    Can you post the code that shows how you are creating your windows? It would be best if you eliminated any extra code and just gave an example that builds and runs.
    Dear Sir

    I have attached compiled & cleaned sample code - FancyWidget.zip(51.6 KB)
    Please help me.

    Thanks
    Santosh
    Attached Files Attached Files

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    OK, try this. I have modified your code in place, so be sure you copy this exactly. There are some changes (like removing WindowStaysOnTopHint) that are not obvious. You will need to do the same for your button widget.

    MainWindow.h:

    Qt Code:
    1. #ifndef _MAINWINDOW_H
    2. #define _MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QPushButton>
    6. #include <QMouseEvent>
    7. #include <QHBoxLayout>
    8. #include <QVBoxLayout>
    9. #include <QLabel>
    10. #include <QDialog>
    11. #include <QPainter>
    12. #include <QBitmap>
    13.  
    14. #include "ui_MainWindow.h"
    15.  
    16. class CustomRoundButtonWidget;
    17. class CustomFrameWidget;
    18.  
    19. class MainWindow:public QMainWindow, public Ui::MainDialog
    20. {
    21. Q_OBJECT
    22. public:
    23. MainWindow(QWidget *parent = 0);
    24. void MoveCustomFrameWidget();
    25.  
    26. protected:
    27. void mouseReleaseEvent(QMouseEvent *event);
    28. void mouseMoveEvent(QMouseEvent *event);
    29. void mousePressEvent(QMouseEvent *event);
    30.  
    31. void closeEvent( QCloseEvent * pEvent );
    32. void showEvent( QShowEvent * pEvent );
    33. void hideEvent( QHideEvent * pEvent );
    34.  
    35. bool event( QEvent * pEvent ) override;
    36.  
    37. private slots:
    38. void OnMinimized();
    39.  
    40. private:
    41. bool IsPointInCaption(const QPoint& point);
    42. private:
    43. QPoint m_dragPosition;
    44. public:
    45. CustomFrameWidget* m_pCustomFrameWidget;
    46. };
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp:

    Qt Code:
    1. #include <QBitmap>
    2. #include <QPainter>
    3. #include <QEvent>
    4. #include <QDebug>
    5.  
    6. #include "MainWindow.h"
    7.  
    8. bool dragged = false;
    9.  
    10. MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
    11. {
    12. setupUi(this);
    13.  
    14. setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    15. setWindowTitle(tr("Fancy Widget"));
    16.  
    17. setMouseTracking(true);
    18. setStyleSheet(
    19. "* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"
    20. "background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 cyan, stop:1 blue);}");
    21.  
    22. QString strMinimize = "QPushButton{border-image: url(:/images/img_TitleMinimize.png)}"
    23. "QPushButton:hover { border-image: url(:/images/img_TitleMinimizeHover.png)}"
    24. "QPushButton:pressed { border-image: url(:/images/img_TitleMinimizePressed.png);}";
    25. MinButton->setStyleSheet(strMinimize);
    26.  
    27. QString strMaximize = "QPushButton{border-image: url(:/images/img_TitleMaximize.png)}"
    28. "QPushButton:hover { border-image: url(:/images/img_TitleMaximizeHover.png)}"
    29. "QPushButton:pressed { border-image: url(:/images/img_TitleMaximizePressed.png);}";
    30. MaxButton->setStyleSheet(strMaximize);
    31.  
    32. QString strClose = "QPushButton{border-image: url(:/images/img_TitleClose.png)}"
    33. "QPushButton:hover { border-image: url(:/images/img_TitleCloseHover.png)}"
    34. "QPushButton:pressed { border-image: url(:/images/img_TitleClosePressed.png);}";
    35. CloseButton->setStyleSheet(strClose);
    36.  
    37. m_pCustomFrameWidget = new CustomFrameWidget();
    38.  
    39. connect( MinButton, SIGNAL( clicked() ), this, SLOT( OnMinimized() ) );
    40. connect( CloseButton, SIGNAL( clicked() ), this, SLOT( close() ) );
    41.  
    42. }
    43. void MainWindow::MoveCustomFrameWidget()
    44. {
    45. m_pCustomFrameWidget->move(this->pos().x() - 40, this->pos().y() + 40);
    46. m_pCustomFrameWidget->show();
    47. }
    48.  
    49. void MainWindow::OnMinimized()
    50. {
    51. m_pCustomFrameWidget->showMinimized();
    52. this->showMinimized();
    53.  
    54. }
    55. void MainWindow::mouseMoveEvent(QMouseEvent *event)
    56. {
    57. QMainWindow::mouseMoveEvent(event);
    58. if(dragged && event->buttons() & Qt::LeftButton)
    59. {
    60. move(event->globalPos()-m_dragPosition);
    61. m_pCustomFrameWidget->move((event->globalPos() - m_dragPosition).x() - 40, (event->globalPos() - m_dragPosition).y() + 40);
    62. event->accept();
    63. }
    64. }
    65. void MainWindow::mouseReleaseEvent(QMouseEvent *event)
    66. {
    67. QMainWindow::mouseReleaseEvent(event);
    68. if(!dragged && event->button() == Qt::LeftButton)
    69. {
    70. if(IsPointInCaption(event->pos()))
    71. {
    72. m_dragPosition = event->pos();
    73. }
    74. }
    75. dragged = false;
    76. }
    77. bool MainWindow::IsPointInCaption(const QPoint & point)
    78. {
    79. QRect captionRect(0,0,800,30);
    80. return (captionRect.contains(point));
    81. }
    82. void MainWindow::mousePressEvent(QMouseEvent *event)
    83. {
    84. if(event->button() == Qt::LeftButton)
    85. {
    86. dragged = false;
    87. QPoint pos = event->globalPos();
    88. if(IsPointInCaption(event->pos()))
    89. {
    90. dragged = true;
    91. m_dragPosition = pos - frameGeometry().topLeft();
    92. }
    93. }
    94. QMainWindow::mousePressEvent(event);
    95. }
    96.  
    97. void MainWindow::closeEvent( QCloseEvent * pEvent )
    98. {
    99. m_pCustomFrameWidget->close();
    100. }
    101.  
    102. void MainWindow::showEvent( QShowEvent * pEvent )
    103. {
    104. m_pCustomFrameWidget->showNormal();
    105. }
    106.  
    107. void MainWindow::hideEvent( QHideEvent * pEvent )
    108. {
    109. m_pCustomFrameWidget->hide();
    110. }
    111.  
    112. bool MainWindow::event( QEvent * pEvent )
    113. {
    114. bool bResult = QMainWindow::event( pEvent );
    115. if ( QEvent::WindowActivate == pEvent->type() )
    116. m_pCustomFrameWidget->raise();
    117. return bResult;
    118. }
    119.  
    120. CustomFrameWidget::CustomFrameWidget(QWidget* parent) :QDialog(parent)
    121. {
    122. setupUi(this);
    123. setWindowFlags(Qt::Window | Qt::FramelessWindowHint );
    124.  
    125. frame->setStyleSheet(
    126. "* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"
    127. "background: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 green, stop:1 darkMagenta);}");
    128.  
    129. this->setAttribute(Qt::WA_TranslucentBackground, true);
    130. }
    To copy to clipboard, switch view to plain text mode 

    The important thing is that all of the widgets must be top-level widgets (or at least have the same parent, in this case the desktop widget since they are created with no parent).

    To make this easier to add more widgets (such as your button), I would create a struct like this:

    Qt Code:
    1. struct AttachedWidget
    2. {
    3. QWidget * mpWidget = nullptr;
    4. QPos mRelativePos = QPos( 0, 0 );
    5. }
    To copy to clipboard, switch view to plain text mode 

    Then I would add a new method and a member variable to MainWindow:

    Qt Code:
    1. public:
    2. void attachWidget( QWidget * pWidget, const QPos & relativePos );
    3.  
    4. private:
    5. QList< AttachedWidget > mAttachedWidgets;
    To copy to clipboard, switch view to plain text mode 

    And modify MainWindow.cpp:

    Qt Code:
    1. void MainWindow::attachWidget( QWidget * pWidget, const QPos & relativePos )
    2. {
    3. AttachedWidget attached;
    4.  
    5. attached.mpWidget = pWidget;
    6. attached.mRelativePos = relativePos;
    7.  
    8. mAttachedWidgets.push_back( attached );
    9. }
    10.  
    11. // and change the methods:
    12.  
    13. void MainWindow::closeEvent( QCloseEvent * pEvent )
    14. {
    15. for ( attachedWidget : mAttachedWidgets )
    16. attachedWidget.mpWidget->close();
    17. }
    18.  
    19. // and so forth for the other events
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 23rd November 2022 at 19:57.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #10
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by d_stranz View Post
    OK, try this. I have modified your code in place, so be sure you copy this exactly. There are some changes (like removing WindowStaysOnTopHint) that are not obvious. You will need to do the same for your button widget.

    MainWindow.h:

    Qt Code:
    1. #ifndef _MAINWINDOW_H
    2. #define _MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QPushButton>
    6. #include <QMouseEvent>
    7. #include <QHBoxLayout>
    8. #include <QVBoxLayout>
    9. #include <QLabel>
    10. #include <QDialog>
    11. #include <QPainter>
    12. #include <QBitmap>
    13.  
    14. #include "ui_MainWindow.h"
    15.  
    16. class CustomRoundButtonWidget;
    17. class CustomFrameWidget;
    18.  
    19. class MainWindow:public QMainWindow, public Ui::MainDialog
    20. {
    21. Q_OBJECT
    22. public:
    23. MainWindow(QWidget *parent = 0);
    24. void MoveCustomFrameWidget();
    25.  
    26. protected:
    27. void mouseReleaseEvent(QMouseEvent *event);
    28. void mouseMoveEvent(QMouseEvent *event);
    29. void mousePressEvent(QMouseEvent *event);
    30.  
    31. void closeEvent( QCloseEvent * pEvent );
    32. void showEvent( QShowEvent * pEvent );
    33. void hideEvent( QHideEvent * pEvent );
    34.  
    35. bool event( QEvent * pEvent ) override;
    36.  
    37. private slots:
    38. void OnMinimized();
    39.  
    40. private:
    41. bool IsPointInCaption(const QPoint& point);
    42. private:
    43. QPoint m_dragPosition;
    44. public:
    45. CustomFrameWidget* m_pCustomFrameWidget;
    46. };
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp:

    Qt Code:
    1. #include <QBitmap>
    2. #include <QPainter>
    3. #include <QEvent>
    4. #include <QDebug>
    5.  
    6. #include "MainWindow.h"
    7.  
    8. bool dragged = false;
    9.  
    10. MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
    11. {
    12. setupUi(this);
    13.  
    14. setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    15. setWindowTitle(tr("Fancy Widget"));
    16.  
    17. setMouseTracking(true);
    18. setStyleSheet(
    19. "* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"
    20. "background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 cyan, stop:1 blue);}");
    21.  
    22. QString strMinimize = "QPushButton{border-image: url(:/images/img_TitleMinimize.png)}"
    23. "QPushButton:hover { border-image: url(:/images/img_TitleMinimizeHover.png)}"
    24. "QPushButton:pressed { border-image: url(:/images/img_TitleMinimizePressed.png);}";
    25. MinButton->setStyleSheet(strMinimize);
    26.  
    27. QString strMaximize = "QPushButton{border-image: url(:/images/img_TitleMaximize.png)}"
    28. "QPushButton:hover { border-image: url(:/images/img_TitleMaximizeHover.png)}"
    29. "QPushButton:pressed { border-image: url(:/images/img_TitleMaximizePressed.png);}";
    30. MaxButton->setStyleSheet(strMaximize);
    31.  
    32. QString strClose = "QPushButton{border-image: url(:/images/img_TitleClose.png)}"
    33. "QPushButton:hover { border-image: url(:/images/img_TitleCloseHover.png)}"
    34. "QPushButton:pressed { border-image: url(:/images/img_TitleClosePressed.png);}";
    35. CloseButton->setStyleSheet(strClose);
    36.  
    37. m_pCustomFrameWidget = new CustomFrameWidget();
    38.  
    39. connect( MinButton, SIGNAL( clicked() ), this, SLOT( OnMinimized() ) );
    40. connect( CloseButton, SIGNAL( clicked() ), this, SLOT( close() ) );
    41.  
    42. }
    43. void MainWindow::MoveCustomFrameWidget()
    44. {
    45. m_pCustomFrameWidget->move(this->pos().x() - 40, this->pos().y() + 40);
    46. m_pCustomFrameWidget->show();
    47. }
    48.  
    49. void MainWindow::OnMinimized()
    50. {
    51. m_pCustomFrameWidget->showMinimized();
    52. this->showMinimized();
    53.  
    54. }
    55. void MainWindow::mouseMoveEvent(QMouseEvent *event)
    56. {
    57. QMainWindow::mouseMoveEvent(event);
    58. if(dragged && event->buttons() & Qt::LeftButton)
    59. {
    60. move(event->globalPos()-m_dragPosition);
    61. m_pCustomFrameWidget->move((event->globalPos() - m_dragPosition).x() - 40, (event->globalPos() - m_dragPosition).y() + 40);
    62. event->accept();
    63. }
    64. }
    65. void MainWindow::mouseReleaseEvent(QMouseEvent *event)
    66. {
    67. QMainWindow::mouseReleaseEvent(event);
    68. if(!dragged && event->button() == Qt::LeftButton)
    69. {
    70. if(IsPointInCaption(event->pos()))
    71. {
    72. m_dragPosition = event->pos();
    73. }
    74. }
    75. dragged = false;
    76. }
    77. bool MainWindow::IsPointInCaption(const QPoint & point)
    78. {
    79. QRect captionRect(0,0,800,30);
    80. return (captionRect.contains(point));
    81. }
    82. void MainWindow::mousePressEvent(QMouseEvent *event)
    83. {
    84. if(event->button() == Qt::LeftButton)
    85. {
    86. dragged = false;
    87. QPoint pos = event->globalPos();
    88. if(IsPointInCaption(event->pos()))
    89. {
    90. dragged = true;
    91. m_dragPosition = pos - frameGeometry().topLeft();
    92. }
    93. }
    94. QMainWindow::mousePressEvent(event);
    95. }
    96.  
    97. void MainWindow::closeEvent( QCloseEvent * pEvent )
    98. {
    99. m_pCustomFrameWidget->close();
    100. }
    101.  
    102. void MainWindow::showEvent( QShowEvent * pEvent )
    103. {
    104. m_pCustomFrameWidget->showNormal();
    105. }
    106.  
    107. void MainWindow::hideEvent( QHideEvent * pEvent )
    108. {
    109. m_pCustomFrameWidget->hide();
    110. }
    111.  
    112. bool MainWindow::event( QEvent * pEvent )
    113. {
    114. bool bResult = QMainWindow::event( pEvent );
    115. if ( QEvent::WindowActivate == pEvent->type() )
    116. m_pCustomFrameWidget->raise();
    117. return bResult;
    118. }
    119.  
    120. CustomFrameWidget::CustomFrameWidget(QWidget* parent) :QDialog(parent)
    121. {
    122. setupUi(this);
    123. setWindowFlags(Qt::Window | Qt::FramelessWindowHint );
    124.  
    125. frame->setStyleSheet(
    126. "* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"
    127. "background: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 green, stop:1 darkMagenta);}");
    128.  
    129. this->setAttribute(Qt::WA_TranslucentBackground, true);
    130. }
    To copy to clipboard, switch view to plain text mode 

    The important thing is that all of the widgets must be top-level widgets (or at least have the same parent, in this case the desktop widget since they are created with no parent).

    To make this easier to add more widgets (such as your button), I would create a struct like this:

    Qt Code:
    1. struct AttachedWidget
    2. {
    3. QWidget * mpWidget = nullptr;
    4. QPos mRelativePos = QPos( 0, 0 );
    5. }
    To copy to clipboard, switch view to plain text mode 

    Then I would add a new method and a member variable to MainWindow:

    Qt Code:
    1. public:
    2. void attachWidget( QWidget * pWidget, const QPos & relativePos );
    3.  
    4. private:
    5. QList< AttachedWidget > mAttachedWidgets;
    To copy to clipboard, switch view to plain text mode 

    And modify MainWindow.cpp:

    Qt Code:
    1. void MainWindow::attachWidget( QWidget * pWidget, const QPos & relativePos )
    2. {
    3. AttachedWidget attached;
    4.  
    5. attached.mpWidget = pWidget;
    6. attached.mRelativePos = relativePos;
    7.  
    8. mAttachedWidgets.push_back( attached );
    9. }
    10.  
    11. // and change the methods:
    12.  
    13. void MainWindow::closeEvent( QCloseEvent * pEvent )
    14. {
    15. for ( attachedWidget : mAttachedWidgets )
    16. attachedWidget.mpWidget->close();
    17. }
    18.  
    19. // and so forth for the other events
    To copy to clipboard, switch view to plain text mode 
    Thanks for provided hint for me. You are really great sir. One issue facing by me...
    Why every time flickering occurs due to raise() function of moving, pressing windows, clicking on other than attached windows. Because attached windows try to raise() so that flickering occurs. Is there any way to raise() silently or smoothly ?
    Plz reply.

    Below is the sample code in which every time pressing AddButton, ResetButton /*(Newly added in Main Window)*/ attached widget go the back of Main window. And then try to raise() all attached windows using below code...
    void MyClass:: OnRaiseWidget()
    {
    foreach(AttachedWidget attchedWidget,pApp.mAttachedWidget)
    {
    if(attchedWidget.pWidget->isVisible())
    attchedWidget.pWidget->raise();
    }
    }

    bool MyClass::eventFilter(QObject* object, QEvent* event)
    {
    if((object == AddButton
    || object == GroupComboBox
    || object == ResetButton) && event->type() == QEvent::MouseButtonPress)
    {
    QMouseEvent *k = static_cast<QMouseEvent *> (event);
    if( k->button() == Qt::LeftButton )
    {
    OnRaiseWidget();
    }
    else if ( k->button() == Qt::RightButton )
    {
    OnRaiseWidget();
    }
    }
    return false;
    }

    On every time pressing, attchedWidget.pWidget->raise(); working ok... but flickering occurs due to attached windows trying to come to front. Is there any way to raise() silently or smoothly or any Qt functions to fix it ?
    Plz reply.
    Last edited by santosh.kumar; 5th December 2022 at 13:34.

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Instead of using a MouseButtonPress event to raise the window, try using WindowActivate. I did not see any flickering in that case, but I was also only using one attached widget. I did not try it with more than one.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  12. #12
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by d_stranz View Post
    Instead of using a MouseButtonPress event to raise the window, try using WindowActivate. I did not see any flickering in that case, but I was also only using one attached widget. I did not try it with more than one.
    Dear Sir

    As I tried using WindowsActivate also but Left panel flicker during pressing of button (Add, Remove, Reset). if you click on Main Window then click on button or vice versa, You can see the effect of left panel flickering due to raise() function. Some time not but almost every times, pressing on button (just after clicking Main Window), flicker occurs. I have created dummy example with added button (Add, remove, Reset) and uploaded the code. I am not getting why this happens when Left panel try to come on front using raise(). if we don't use raise(), it just go behind the main window.
    I have tried on another widgets also and just pressing on that widgets, for few moments left panel flickers which look like very awkward.
    Please tell me the solution. I have attached code 'FancyWidget-15-dec'.

    Thanks
    Santosh
    Attached Files Attached Files

  13. #13
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by santosh.kumar View Post
    Dear Sir

    As I tried using WindowsActivate also but Left panel flicker during pressing of button (Add, Remove, Reset). if you click on Main Window then click on button or vice versa, You can see the effect of left panel flickering due to raise() function. Some time not but almost every times, pressing on button (just after clicking Main Window), flicker occurs. I have created dummy example with added button (Add, remove, Reset) and uploaded the code. I am not getting why this happens when Left panel try to come on front using raise(). if we don't use raise(), it just go behind the main window.
    I have tried on another widgets also and just pressing on that widgets, for few moments left panel flickers which look like very awkward.
    Please tell me the solution. I have attached code 'FancyWidget-15-dec'.

    Thanks
    Santosh
    Please reply.

  14. #14
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Please reply.
    Sorry, I have been busy with my own work and have not had time to look at this. Maybe someone else can pick it up.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  15. #15
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by d_stranz View Post
    Sorry, I have been busy with my own work and have not had time to look at this. Maybe someone else can pick it up.
    Dear Sir

    Plz reply once you will be free from your works. I can wait, no issue.

    Thanks
    Santosh Kumar Singh

  16. #16
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by santosh.kumar View Post
    Dear Sir

    Plz reply once you will be free from your works. I can wait, no issue.

    Thanks
    Santosh Kumar Singh
    Any solution for flickering query ?

  17. #17
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Sorry again, but I am under a deadline for my own work and have no free time. I think you will have to solve this yourself or find a different UI design if you can't solve it. I don't recommend waiting for me.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  18. #18
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    Quote Originally Posted by d_stranz View Post
    Sorry again, but I am under a deadline for my own work and have no free time. I think you will have to solve this yourself or find a different UI design if you can't solve it. I don't recommend waiting for me.
    From your initial guidance, my application is almost ready.
    But i have used finally setWindowFlags of Qt::Tool | Qt::FramelessWindowHint for Left FRame Panel.
    Its working without raise().

    But our problem is that Qt::Tool windows hides in inactive mode.
    for this I have used setAttribute(Qt::WA_MacAlwaysShowToolWindow, true);
    In both active/inactive mode of application, it always show.

    I m working in Mac, If Application is in active mode, if click on dock icon and click on Show All Windows - Only Main window show and left panel not show due to Qt::Tool, Its OK

    But if Application is in inactive mode, if click on dock icon and click on Show All Windows - Both Left Panel and main windows show but both show separately. I don't want this .
    I want that inactive mode also, it should Only Main window show and left panel not show due to Qt::Tool. or else Left Panel should not loose their parent and should not show as a separate window.
    Sir, Please tell me the solution.

  19. #19

    Default Re: How any widget/frame/button to be displayed/look like outside boundary of main wi

    It seems like you want the left panel (Qt::Tool window) to stay associated with the main window even when the application is in inactive mode. To achieve this, you can try using the Qt::WindowStaysOnTopHint flag in combination with Qt::Tool. This way, the left panel will stay on top of the main window and won't disappear when the application is inactive.

    Here's an example of how you can set the window flags for the left panel:

    cpp
    Copy code
    Qt Code:
    1. leftPanelWidget->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
    To copy to clipboard, switch view to plain text mode 
    This will keep the left panel as a tool window that stays on top, even in inactive mode. Make sure to adjust the code according to your application's structure.

    Give it a try, and see if it resolves the issue you're facing.
    Last edited by d_stranz; 4th January 2024 at 22:07. Reason: missing [code] tags

Similar Threads

  1. How to remove frame of main window widget
    By akhilteja in forum Newbie
    Replies: 1
    Last Post: 26th August 2013, 08:51
  2. Replies: 6
    Last Post: 12th August 2013, 19:13
  3. Replies: 3
    Last Post: 23rd December 2010, 07:55
  4. Add a Frame Widget to the main window
    By kamlmish in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2010, 09:51
  5. Main Window frame height
    By ^NyAw^ in forum Qt Programming
    Replies: 18
    Last Post: 13th November 2007, 13:14

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.