Unsolved Resize the "setGeometry" from cpp
-
Hai everyone. I want to resize my widget by its geometry. This is the code
void MainGUI::resizeEvent(QResizeEvent *e) { heightsize = e->size().height(); float spacing = heightsize/700.0; QWidget * channel = new QWidget(this); channelFrame * cF = new channelFrame(channel); cF->setGeometry(10, 40 + ( 75 * spacing), 1115, 35); cF->show(); }
But it also add the widget, not resizing it. how can I only resize the spacing? Sorry I'm a newbie here
-
@mimamrafi
Hello and welcome.But it also add the widget
You go
QWidget * channel = new QWidget(this);
, so, yes, that creates and adds a new widget.We don't know what your
new channelFrame(channel)
is.I want to resize my widget
What widget? Some existing one?? The newly created
channel
one? The newly createdchannelFrame
, which we don't even know whether it is a widget? -
@mimamrafi In Qt, if you are manually resizing widgets inside other widgets then you are usually going about your UI the wrong way. Qt has a layout system to arrange contained widgets and this is almost always a set-and-forget problem.
-
@JonB the channelFrame is a class that contain many widget.
this is the channelframe.ui and I created it repeatedly. Like this
And I want the channelSpacing more wider when size changed to be like this
You are right it cannot be solved because I just create new widget again. How to update my widget? How to avoid "new" QWidget? i'm so sorry this is my senior code and I'm newbie in QT
-
@ChrisW67 I know there's layout feature, but in my case I have to make it dynamic from cpp
-
@mimamrafi
It's difficult to answer your questions. You need a basic understanding of Qt and widgets, which seems to be lacking.How to update my widget? How to avoid "new" QWidget?
Do whatever on your existing widget, don't create a new one. Can't answer any clearer than that.
I know there's layout feature, but in my case I have to make it dynamic from cpp
QLayout
s can be created from C++ code, not just from e.g. Qt Designer/.ui
file. You should be doing all of your desired layout via suitableQLayout
s, notsetGeomtetry()
or any coordinate positioning of widgets, as @ChrisW67 indicated. Your case looks like aQGridLayout
. -
@mimamrafi Can you confirm that you want the individual sub-widgets (i.e. the Off, +, - buttons, sliders etc.) to stay exactly the same size and only the space between them to grow if the total available space grows?
Can you post the UI file that you seem to have for your channelFrame?
-
@ChrisW67 I'm using another method, I'm not reccommend this method because its for newbie like me. hehe. So I build one per one of channel frame like this...
I think it solved but I have to make more codes for this methods