I'm working on an Qt app. I should create a pop-up window that has only a close button with no toolbar, minimize and maximize buttons.
Any idea how to do this?
I don't know by "no toolbar" you mean "no title bar" or not, but this example can help you. Anyway, by using the following code you can have a window with just close button, and "title bar":
window->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);
If you don't want the title bar too, try to remove it and design it by yourself.
you could change the window-flags. But your expected window calls for a QDialog: has no menu-bar and just a close-button (out of the box).
Else refer to this ( https://doc.qt.io/qt-5/qtwidgets-widgets-windowflags-example.html ) and set the flag for Qt::WindowCloseButtonHint.
If you use setWindowFlags(Qt::Window | Qt::FramelessWindowHint); you will get rid of the title bar, but with it all buttons that live on the titlebar, including the close button.
This will mean you will need to implement a way to move the window, as the title bar is used for this purpose. See this answer
Then implement your own titlebar class with a close button that you can put at the top of your dialog.
Unfortunately you don't have any control over the system titlebar appearance, so it's not possible to stylesheet your way out of this problem.
Related
I have a CMFCColorButtoninside a CPropertyPage. When I click the button, the color choice popup comes up. I can select a color and the popup closes, I can get the color etc.. all good. But when I click somewhere else while the popup is open, it doesn't close. Which it should - what's going in?
I know this problem from when you use this special popups in a dialog. You must use CDialogEx instead of CDialog.
CDialogEx uses OnNcActivate with a CDialogImpl class that closes popups.
As I see the same handling is used in CMFCPropertySheet and CMFCPropertyPage.
SO the solution should be using CMFCPropertySheet and CMFCPropertyPage instead of the CProperty... classes.
I currently have a Qt::Dialog with a What's This help button, and a close button in the title bar.
I tried modifying the window hint flags to include the maximise and minimise buttons as well.
This worked but removed the What's This button, even if I explicitly included the flag for the what's this button as well.
Is there any way that I can have a dialog with maximise and minimise buttons but keep the What's this functionality?
If you don't mind where the What's this button appears, you can create a new button anywhere (probably called "What's This" or just "?").
This new button must be connected to a slot that includes the function:
`QWhatsThis::enterWhatsThisMode();`
which will perform the same function as the now missing What's This button in the title bar.
It probably is the only function the slot needs to call.
This action can even be called from a menu, and if required from a key combination.
I have a design like below:
So basically, I want to embed three dialogs in the application main dialog and switch between them, for each button click i.e., button 1 will show dialog one , button 2 will hide dialog 1 and show dialog 2 .. and so on.
Each dialog will be having a different design and functions.
I tried using CPropertySheet class to Add pages but its GUI is different. It has either option for navigating the dialogs using next / back button , or from a tab control.
None of which is as per my requirement.
So I want to know is it possible to have a design like this in MFC ? If yes how? Which Class/ control should I use.
Any help will be appreciated.
What you can do is use a normal CDialog class, add your buttons to it and also create a frame/rect as a placeholder for where your embedded dialogs are to appear. The following piece of code will create and position your embedded dialog.
CRect rect;
CWnd *pHost = GetDlgItem(ID_OF_YOUR_FRAME_RECT);
pHost->GetWindowRect(&rect);
ScreenToClient(&rect);
pDialog->Create(ID_OF_YOUR_DIALOG, this);
pDialog->MoveWindow(&rect);
pDialog->ShowWindow(SW_SHOW);
On button clicks, you hide the previously shown dialog (SW_HIDE) and show your selected dialog(SW_SHOW) with ShowWindow(...).
If you create your embedded dialogs with IDD_FORMVIEW style in the add resource editor it'll have the proper styles for embedding.
Another option is probably to use an embedded PropertySheet and hide the tab row and programatically change the tabs on the button clicks. I just find it to be too much fuzz with borders, positioning, validation and such for my liking.
If you have the MFC Feature Pack, that first came with VS2008 SP1 and is in all later versions, you might like to consider CMFCPropertySheet. There are a number of examples on the linked page, that are very similar to your design.
For example, this:
What worked for me just using dialog based application is SetParent() method. Dont know why nobody mentioned it. It seems to work fine.
I am doing like below:
VERIFY(pDlg1.Create(PanelDlg::IDD, this));
VERIFY(pDlg2.Create(PanelDlg2::IDD, this));
VERIFY(pDlg3.Create(PanelDlg2::IDD, this));
::SetParent(pDlg1.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg2.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg3.GetSafeHwnd(), this->m_hWnd);
Now I can show or hide a child dialog at will (button clicks) as below:
pDlg1.ShowWindow(SW_SHOW);
pDlg2.ShowWindow(SW_HIDE);
pDlg3.ShowWindow(SW_HIDE);
I have a hard time hiding a modal dialog box. What I am doing is - I am trying to design a UI for my own application in MFC, kind of a setup assistant.
In the 1st dialog box I have NEXT button, so when I click that it has to hide the 1st dialog box and move on to the 2nd dialog box, where I have some controls in 2nd dialog box.
How can I achieve that?
I have never tried to hide a Modal dialog...not sure how it can be done.
Anyway, it seems to me you don't need to hide the dialog but destroy the first one and create the second one. You can use EndDialog to terminate a modal dialog.
But MFC has its own mechanism to create your own wizard, have a look at this class CPropertySheet. I am sure you can find thousand of examples, this is one.
Hope it helps.
You can use ShowWindow() function to hide modal
Its default patametet is SW_SHOW which is equal true value 1 and
To hide modal use SW_HIDE value when you click next button
You just use ShowWindow(SW_HIDE) If you make prev button you should use modal pointer
Or next modal should child modal because you cannot have prev modal variable.
I wish you understand me for my english
i have a button that is a rectangle how would i put words in it i want to make so ican click the word and it starts the progrma i know ShellExecute the style is BS_GROUPBOX
If you have more than one program you want to start, you need a button per program you want to start.
To start you external progrma, in the button parent window, you need to process the WM_COMMAND message with the BN_CLICKED notification.
To set the text of the button, you need to send WM_SETTEXT message to the button with the text you want shown.
Btw, BS_GROUPBOX is used for creating the rectangle around radio buttons. This style is not going to work for your scenario.
If you want an alternative to using multiple Button controls, you can use a Toolbar. In fact, it seems to me that a toolbar would be a better control for you. You can read more about creating a toolbar.