Blank client area
-
I've just finished converting more of my code to Qt. Problem is that now the client area of the main window is blank (white).
The code that sets up the main parts of the client area is as follows:
widget = new QWinWidget(this); widget->showCentered(); ZTRACE_RUNTIME("Creating Explorer Bar (Left Panel)"); explorerBar = new ExplorerBar(widget); ZTRACE_RUNTIME("Creating Explorer bar - ok"); ZTRACE_RUNTIME("Creating Stacking Panel"); stackingDlg = new DSS::StackingDlg(widget); ZTRACE_RUNTIME("Creating Stacking Panel - ok"); ZTRACE_RUNTIME("Creating stackedWidget"); stackedWidget = new QStackedWidget(widget); ZTRACE_RUNTIME("Adding Stacking Panel to stackedWidget"); stackedWidget->addWidget(stackingDlg); ZTRACE_RUNTIME("Creating Horizontal Splitter"); splitter = new QSplitter(Qt::Horizontal, widget); splitter->addWidget(explorerBar); splitter->addWidget(stackedWidget); splitter->setStretchFactor(1, 1); // Want Stacking part to take any spare space. splitter->show();
What have I not done that I should have done?
The code that worked previously where the only Qt stuff was in the ExplorerBar looked like:
widget = new QWinWidget(this); widget->showCentered(); explorerBar = new ExplorerBar(widget); ZTRACE_RUNTIME("Creating Explorer bar - ok");
the other windows in that case were MS window objects.
-
Hi,
I haven't used the class but I would set a layout (for examples QVBoxLayout) on your QWinWidget object and add your splitter to it.
-
Looks like your client area is not fully expanded, is it ?
-
? Not sure I understood that ? I'm sure when you explain it will be abundantly clear.
The bit that is displayed looks like it may be part of the Explorer Bar (specifically where it says "Register checked pictures"):
I expected the Explorer Bar to occupy the left 1/3 (or so) of the client area.
D. -
This is the current code which added a QVBoxLayout to the QWinWidget as SGaist suggested:
widget = new QWinWidget(this); QVBoxLayout* layout { new QVBoxLayout() }; ZTRACE_RUNTIME("Creating Horizontal Splitter"); splitter = new QSplitter(Qt::Horizontal, widget); widget->setLayout(layout); ZTRACE_RUNTIME("Creating Explorer Bar (Left Panel)"); explorerBar = new ExplorerBar(widget); ZTRACE_RUNTIME("Creating Explorer bar - ok"); ZTRACE_RUNTIME("Creating Stacking Panel"); stackingDlg = new DSS::StackingDlg(widget); ZTRACE_RUNTIME("Creating Stacking Panel - ok"); ZTRACE_RUNTIME("Creating stackedWidget"); stackedWidget = new QStackedWidget(widget); ZTRACE_RUNTIME("Adding Stacking Panel to stackedWidget"); stackedWidget->addWidget(stackingDlg); stackedWidget->setCurrentWidget(stackingDlg); splitter = new QSplitter(Qt::Horizontal, widget); splitter->addWidget(explorerBar); splitter->addWidget(stackedWidget); splitter->setStretchFactor(1, 1); // Want Stacking part to take any spare space. stackedWidget->show(); splitter->show(); widget->showCentered();
Are you suggesting I need to add layouts to the Splitter? Do I need to size the QWinWidget to the size of the Windows client area (didn't need to before when the only control I added as a child of the QWinWidget was the ExplorerBar).
Thanks
David -
@Perdrix said in Blank client area:
Are you suggesting I need to add layouts to the Splitter?
No, you need to add the splitter to a layout.
And do you have a layout on "this"? You're added "widget", but is it part of any layout? -
I haven't got a layout set on "this" because *this is an MFC CDialog - hence the use of a QWinWidget to act as a message pump and owner of Qt Widgets.
Here's the code as it now stands after some experimentation:
widget = new QWinWidget(this); QVBoxLayout* verticalLayout { new QVBoxLayout(widget) }; verticalLayout->setObjectName("verticalLayout"); ZTRACE_RUNTIME("Creating Horizontal Splitter"); splitter = new QSplitter(Qt::Horizontal, widget); splitter->setObjectName("splitter"); ZTRACE_RUNTIME("Creating Explorer Bar (Left Panel)"); explorerBar = new ExplorerBar(splitter); explorerBar->setObjectName("explorerBar"); splitter->addWidget(explorerBar); ZTRACE_RUNTIME("Creating stackedWidget"); stackedWidget = new QStackedWidget(splitter); stackedWidget->setObjectName("stackedWidget"); ZTRACE_RUNTIME("Creating Stacking Panel"); stackingDlg = new DSS::StackingDlg(stackedWidget); stackingDlg->setObjectName("stackingDlg"); ZTRACE_RUNTIME("Adding Stacking Panel to stackedWidget"); stackedWidget->addWidget(stackingDlg); stackedWidget->setCurrentWidget(stackingDlg); splitter->addWidget(stackedWidget); splitter->setStretchFactor(1, 1); // Want Stacking part to take any spare space. verticalLayout->addWidget(splitter); //stackedWidget->show(); //splitter->show(); widget->showCentered();
The result rather surprised me:
The StackingDlg has ended up as free-floating window (top-left) when I expected it to be to the RHS of the ExplorerBar. The other thing is how to get it to fill the client area? ExplorerBar has SizePolicy (Preferred, Expanding) and StackingDlg has (Expanding, Expanding).
-
@Perdrix said in Blank client area:
The StackingDlg has ended up as free-floating window
How do you show StackingDlg? And does it have a parent?
-
@jsulm stackingDlg = new DSS::StackingDlg(stackedWidget);
So yes it has a parent of the stackedWidget whose parent in turn is the splitter.
As you can see from the code I posted.
It will be shown when the QWinWidget is shown by the call to showCentered() (won't it?).
D.
-
Can you show the code where you create the hierarchy ?
I am currently unsure that you are using QWinWidget at the right place. -
Here you go:
BOOL CDeepStackerDlg::OnInitDialog() { ZFUNCTRACE_RUNTIME(); ZTRACE_RUNTIME("Initializing Main Dialog"); CDialog::OnInitDialog(); ZTRACE_RUNTIME("Initializing Main Dialog - ok"); widget = new QWinWidget(this); QVBoxLayout* verticalLayout { new QVBoxLayout(widget) }; verticalLayout->setObjectName("verticalLayout"); ZTRACE_RUNTIME("Creating Horizontal Splitter"); splitter = new QSplitter(Qt::Horizontal, widget); splitter->setObjectName("splitter"); ZTRACE_RUNTIME("Creating Explorer Bar (Left Panel)"); explorerBar = new ExplorerBar(splitter); explorerBar->setObjectName("explorerBar"); splitter->addWidget(explorerBar); ZTRACE_RUNTIME("Creating stackedWidget"); stackedWidget = new QStackedWidget(splitter); stackedWidget->setObjectName("stackedWidget"); splitter->addWidget(stackedWidget); ZTRACE_RUNTIME("Creating Stacking Panel"); stackingDlg = new DSS::StackingDlg(stackedWidget); stackingDlg->setObjectName("stackingDlg"); ZTRACE_RUNTIME("Adding Stacking Panel to stackedWidget"); stackedWidget->addWidget(stackingDlg); stackedWidget->setCurrentWidget(stackingDlg); splitter->setStretchFactor(1, 1); // Want Stacking part to take any spare space. verticalLayout->addWidget(splitter); stackedWidget->show(); splitter->show(); widget->move(0, 0); widget->show();
What's really weird is that if I grab the splitter bar next to the "ExplorerBar", and move it to the right, the StackingDlg Window is changed as if it were not a separate window.
-
The thing that I find strange in your code is
widget = new QWinWidget(this);
. QWinWidget takes an HWND as first parameter which I suspectthis
is not and that is likely the source of your issue. -
The QWinWidget ctor I'm using eats a CWnd*
QWinWidget::QWinWidget(CWnd *parentWnd, QObject *parent, Qt::WindowFlags f)
and as a CDialog sub-class, the this pointer will definitely point to a CWnd.
So I don't believe that's the issue (and I don't think the compiler would have let me pass a CWnd* to a ctor that ate an hwnd)
D. -
I know you probably wouldn't normally do so, but given how oddly this is behaving, if you want to debug this problem you can download the entire project which builds with VS2019 (Community edition), Qt VSTools and Qt 15.5.2 from:
https://github.com/deepskystacker/DSS/tree/master/DeepSkyStacker
The project to build would be the DeepSkyStacker project (Debug, x64).
The "solution" file is DeepSkyStacker.VS2019.sln
The code in question is in DeepStackerDlg.cpp at line 266 and following:
D.
-
I currently do not have a Windows machine at hand so I can't check that directly.
Did you consider starting from the QWinWidget example and build something similar to that dialog to see where it starts behaving strangely ?