BUMP - how to code "main window display area "?
-
I like to use / reuse the QMainWindow area - between tool bar icons and status bar - to add widgets into.
.
Does it have an official name ?
How do I get its size ?I prefer NOT to disrupt working QDesigner ui setup...
This code takes the entire area
setCentralWidget(m_console);
and I like to share the SAME area with more widgets.
and example code or link would be nice
Thanks
-
@AnneRanch
mainWindow->show(); dDebug() << mainWindow->centralWidget()->size();
-
@AnneRanch
You make it aQWidget
, you set some layout on it, you addconsole
widget somewhere on layout and you can add whatever other widgets you like elsewhere on layout. -
@AnneRanch said in BUMP - how to code "main window display area "?:
and I like to share the SAME area with more widgets.
Already asked and answered here two times:
https://forum.qt.io/topic/155963
https://forum.qt.io/topic/155559 -
@JonB Here is my current TEST code:
QPushButton* but1 = new QPushButton("Button 1"); QPushButton* but2 = new QPushButton("Button 2"); QPushButton* but3 = new QPushButton("Button 3"); this->layout()->addWidget(but1);
It uses "this" layout and "takes over: the entire area " = including the menu and icons bars. No good.
I can (probably ) move the button around, but I want to keep the menus and icons,
When I build another layout
// QHBoxLayout *layout = new QHBoxLayout;
// layout->addWidget(but2);
// layout->setEnabled(true);
// this->setLayout(layout);I get same " wiped out whole area " but NO button.
I do not want to ask yes /no questions , nor (care for ) receiving statistical data,
but
do I really need to code another "layout" - on top of the "this" default "layout (manger ) " ?Thanks
-
@AnneRanch
QWidget *widget = new QWidget; setCentralWidget(widget); QVBoxLayout *layout = new QVBoxLayout(widget); // or whatever layout kind you want layout->addWidget(console); layout->addWidget(someotherwidget); layout->addWidget(somePushButton); ....
Now you have multiple widgets in the main window central layout, instead of just
console
. That's how you do it if that is what you want. You can also do this from Designer.this->setLayout(layout);
will never be right ifthis
is aQMainWindow
, but I don't know what yourthis
is. -
@AnneRanch
this->layout()
…is the main window layout, which isn’t meant to host other apps widgets. That’s what the central widget and its layout is supposed to handle. It also gives you the freedom to choose if it’s vertical, horizontal, or a grid. „Coding another layout“ is a two liner. Why are you reluctant about it?
-
Addendum PROGRESS UPDATE
OK, I finally got the picture and it is working.
However, I got spoil using QDesigner for ui...
I decided to combine code and QDesigner.For now I have the original m_console and newly build TAB widget class using QDesigner...
Small issue
I cannot get BOTH m_console and m_form_tab to show up TOGETHER ....only one or the other , not both
what am I missing ?
// build ui form m_form_tab = new Form_TAB(); m_form_tab->show(); // test widgets QPushButton* but1 = new QPushButton("Button 1"); QPushButton* but2 = new QPushButton("Button 2"); QPushButton* but3 = new QPushButton("Button 3"); QWidget *widget = new QWidget; setCentralWidget(widget); QVBoxLayout *layout = new QVBoxLayout(widget); /// layout->addWidget(m_console); **layout->addWidget( m_form_tab); no go ! layout->addWidget(m_console);**
-
Good that you have it working and thanks for letting us know!
If you write a post, please re-read it before posting and put yourself in the position of someone who tries to help you.
Had you done it this time, you may have realized that you don’t tell, whatm_console
is. Where it’s declared, instantiated, if you have ever shown it before or done other things with it.
How do you think anybody can answer your question without this critical piece of information?
-
UPDATE
I have narrowed it down to TAB widget....
STAND BY