I'm curious as to how calling "delete button;" @7:11 works. It's just freeing the memory at the pointer, not even setting the pointer to null and definitely not informing the parent frame that it has been deleted. How is that working properly here? Is it better to use removeWidget()?
I understand what your concern is. I believe when the object is being deleted, that handles the "inform the parent" part, which does the rest of the work to remove it and so on. I don't remember exactly, but you could remove widget and then delete the pointer afterwards. I do think that simply deleting it handles the rest just because they have parent/child references to each other.
thanks for the video man, i want to make the user select the checkboxes and one additional button click to delete the layout and the widgets on the selected checkboxs hashmap. how can i do such thing ? connecting signal to signal and then signal to slot maybe ? can you give me an idea ?
You can follow the same approach on the video. You should be able to know which check boxes are checked (by checking if they're checked), and, if they are, you delete them and the layout/widget they're in.
Good question, I am not 100% sure, but you shouldn't need to delete all the children of the widget when deleting the parent widget. This is because in Qt, when you delete the parent, the parent deletes its children (and the children of those children and so on). You can ensure this by making the upper widget the parent of the child widget. I am not sure if Qt does this automatically when you add a widget to another widget.
what a beautiful work! But I keep get warning QLayout: Attempting to add QLayout "" to QFrame "frame", which already has a layout After I added QHBoxLayout* layout = new QHBoxLayout(ui->frame); in my code. Any help ??
@Velcode i added set of hboxlayout with number of combobox to a vhbox layout. i have set this as layout for tablewidget. i have two seperate buttons for add and delete items. i am able to add the hboxlayout everytime when i click add. But i am unable to delete the item. please can you help me. Insteat of tablewidget i use frame and groupbox also... in all cases i can add the new set of hboxlayout in the existing layout. but i am not able to delete the items
Umm, I would have to see what you are doing. There must be something you're not deleting which keeps it there. There are various things that could be going wrong. When you delete, do you delete everything properly liked I showed in the video?
if i add gifs and pictures from my resource file to my qt project how do i compress the resource file so my app is smaller in MB and also works flawlessly
I am not aware of a way to save a widget created on run time. You would have to define that yourself (store what you are trying to save on a text file and load it on the next run).
i have qt 5.15.2 in Visual studio and i don't know why but i don't have any statusbar as all of the guys in the youtube tutorials how do i add one?? i*ve also puttet the question in stackoverflow
Never have messed with audio or video, but I think Qt has classes for those things. The click can be captured, which you can then use to show the video/sound.
@@lopo8000 Yes, you can use a timer that, when the timer is up, you disable the image. The image can be loaded using the Qt image loading classes (similar to icons).
@@VelcodeCS maybe it's impudent. but I want to ask one more question. can I add buttons to the beginning of the model and not to the end? I pasted verticalSpaser into my layout so the buttons are at the top. and buttons are added from the bottom = /
@@S-Pohilenko I'm not sure exactly what you're trying to do. However, in a container (with a layout), items are indexed based on their position (top to bottom in vertical, left to right in horizontal). So, when you add items, you simply put the index of where in the layout it should be inserted to. Do consider that spacers, although not visible, are part of the items in the layout (it has an index as well). So, if you want the new added buttons at the very top, you always insert at 0. If you want inserted at the bottom of all the previously inserted buttons, but above the spacer, you insert at number of items - 2.
In the second part of the video, you can see how to do that. Now, if you're simply trying to make it visible, then you can enable/disable it instead of creating and adding. It should be simpler.
@@VelcodeCS yes.. thank you.. made a mistake of not inserting the table onto a QHash.. so solved it.. thank you for all your input.. it really changed the way i use my logic while coding..although i have a new additional questions... Is it a good practice to have lot of QHashs for various dynamic widgets.. will it impact performance in long run.. do i need to keep checking if those Qhash maps are being used..and if not should i erase them to free up memory spaces due to those unused QHash memory pointers
@@Mdzab2000 I like to use hash maps to quickly have access to different items. Ideally, you want to remove items from the map as you stop using them. For me, when I use them, when I create the item (say, a widget in your case), I add it to the hash map. Then, once I no longer need it, I remove it as part of its deletion (right before it). There is no benefit to keep unused data any more. Not sure what you are implementing, but it's how I generally use the QHash. Create, insert, use, remove, delete. Keep it clean! :D
@@VelcodeCS i added set of hboxlayout with number of combobox to a vhbox layout. i have two seperate buttons for add and delete items. i am able to add the hboxlayout everytime when i click add. But i am unable to delete the item. please can you help me.
Frames have visual properties (background color, margins, etc.). Layouts do not. Frames also have a main layout within them to organize the UI elements within them (which is off by default). I hope this helps.
Hi there, somehow my qobject_cast() seems not to be worked and it makes the application crashed. why is it happenning I don't know. If I comment out the line then it works. void MainWindow::onAddWidget() { QVBoxLayout *layout = qobject_cast(ui->frame->layout()); QString buttonText = tr("Button #%1").arg(layout->count()); QPushButton* button = new QPushButton("buttonText",ui->frame); layout->insertWidget(0,button); } I am using qt 6.4.0 mingw 64 Thanks in advance💕💕
So it's probably one of two possible issues, your ui frame's layout is not a QVBoxLayout or your ui object is null. Makes sure your widget is properly set up and you're using the right classes.
@@VelcodeCS Thank you so much for your response! ❤️ I would like to request you to make it, please :) And it is truly highly appreciated from my side - sure please take your time, i know you got this 😊 tbh I will be waiting for it 👍
Not a bad idea! I've been wanting to work on some more Qt videos but have been busy. Fortunately the semester is over, so I should have some time to make some more!
Wow this was exceptionally clear and concise, and you touch quickly on everything that might otherwise be confusing or unclear.
Watched this just at the right time for me to learn a thing or two. Thank you!
I'm curious as to how calling "delete button;" @7:11 works. It's just freeing the memory at the pointer, not even setting the pointer to null and definitely not informing the parent frame that it has been deleted. How is that working properly here? Is it better to use removeWidget()?
I understand what your concern is. I believe when the object is being deleted, that handles the "inform the parent" part, which does the rest of the work to remove it and so on.
I don't remember exactly, but you could remove widget and then delete the pointer afterwards. I do think that simply deleting it handles the rest just because they have parent/child references to each other.
Among the best videos on QT, Tnx
i love your qt series man ,keep doing them if you can👍
Glad to be of help! I do plan to keep posting the things I've learned while using this framework.
thanks for the video man, i want to make the user select the checkboxes and one additional button click to delete the layout and the widgets on the selected checkboxs hashmap. how can i do such thing ? connecting signal to signal and then signal to slot maybe ? can you give me an idea ?
You can follow the same approach on the video. You should be able to know which check boxes are checked (by checking if they're checked), and, if they are, you delete them and the layout/widget they're in.
if inside the layout you had more layouts, should you do it by recursion or just deleting the top widget is enough?
Good question, I am not 100% sure, but you shouldn't need to delete all the children of the widget when deleting the parent widget. This is because in Qt, when you delete the parent, the parent deletes its children (and the children of those children and so on). You can ensure this by making the upper widget the parent of the child widget. I am not sure if Qt does this automatically when you add a widget to another widget.
what a beautiful work! But I keep get warning
QLayout: Attempting to add QLayout "" to QFrame "frame", which already has a layout
After I added QHBoxLayout* layout = new QHBoxLayout(ui->frame); in my code.
Any help ??
Oh my god thank you, this video is so well done and clearly explained. All props to you man :) !!
@Velcode i added set of hboxlayout with number of combobox to a vhbox layout. i have set this as layout for tablewidget. i have two seperate buttons for add and delete items. i am able to add the hboxlayout everytime when i click add. But i am unable to delete the item. please can you help me.
Insteat of tablewidget i use frame and groupbox also... in all cases i can add the new set of hboxlayout in the existing layout. but i am not able to delete the items
Umm, I would have to see what you are doing. There must be something you're not deleting which keeps it there. There are various things that could be going wrong. When you delete, do you delete everything properly liked I showed in the video?
thank you, if i wanna to delete a frame what is the slot and signal should be please reply
What do you mean? You can add your own signal and slot which handles the removal of the frame. Is this what you're referring to?
thx algorithm... was just thinking about this
how to make a counter active checkBox?
Thank you man, I was stuck in my project and this video helped me figure out everything. 1 subscribe from me 👍👍👍
if i add gifs and pictures from my resource file to my qt project how do i compress the resource file so my app is smaller in MB and also works flawlessly
You could compress your images
good tutorial ! save my time a lot ! keep it up 👍
How to save current UI with different dynamics added widgets ?.Thanks !
I am not aware of a way to save a widget created on run time. You would have to define that yourself (store what you are trying to save on a text file and load it on the next run).
@@VelcodeCS thanks for reply
@@rafaelhakobyan2848 no problem! Consider using a Json file for this task.
i have qt 5.15.2 in Visual studio and i don't know why but i don't have any statusbar as all of the guys in the youtube tutorials how do i add one?? i*ve also puttet the question in stackoverflow
You're probably not using a main window and using a widget instead.
@@VelcodeCS how do i add multiple images in a label?
Do u know how to when the user clicks on o radio box or on a button or label to display a video or a sound effect from a meme.
Never have messed with audio or video, but I think Qt has classes for those things. The click can be captured, which you can then use to show the video/sound.
@@VelcodeCS is there a easy way to display a gif when a button is clicken and then hide it after a specific time?
@@lopo8000 Yes, you can use a timer that, when the timer is up, you disable the image. The image can be loaded using the Qt image loading classes (similar to icons).
how do i add a radio button box and then say to add oder subbuttons to say how much gold i want
I have no idea what you're doing.
@@VelcodeCS let's say i click on change camera hack mod and i want to set it to 2 one click sets it to 1 but i also want to set it to 3,4 and so on
Hello! You can publish the project somewhere?
I'll put it on a GitHub repository and let you know.
I put a link to the repository on the video description :)
@@VelcodeCS Thank you very much!
@@VelcodeCS maybe it's impudent. but I want to ask one more question. can I add buttons to the beginning of the model and not to the end? I pasted verticalSpaser into my layout so the buttons are at the top. and buttons are added from the bottom = /
@@S-Pohilenko I'm not sure exactly what you're trying to do. However, in a container (with a layout), items are indexed based on their position (top to bottom in vertical, left to right in horizontal). So, when you add items, you simply put the index of where in the layout it should be inserted to. Do consider that spacers, although not visible, are part of the items in the layout (it has an index as well).
So, if you want the new added buttons at the very top, you always insert at 0. If you want inserted at the bottom of all the previously inserted buttons, but above the spacer, you insert at number of items - 2.
How to do when click the button it show whole layout ( which include label inside) ?
In the second part of the video, you can see how to do that. Now, if you're simply trying to make it visible, then you can enable/disable it instead of creating and adding. It should be simpler.
@@VelcodeCS Thanks a lot ! You saved my life :")
Very good. Insert item at number n would be good to know how to do
It turns out insertWidget is a thing in pyside6, but no doco seems to have it
i want to redifine how do i stop example QMovie* movie("") so i can declare a new movie and shoot more movies inside like a uzi
I have no idea what you are talking about
Can i dynamically add QTableWidget and insert /modify/change its items(contents) from another slot using QHash map
Yes it is possible to do so. You have to also set the headers (horizontal and vertical, whichever you need). Then you can insert items as rows.
Saw your comment, I am assuming you figured it out?
@@VelcodeCS yes.. thank you.. made a mistake of not inserting the table onto a QHash.. so solved it.. thank you for all your input.. it really changed the way i use my logic while coding..although i have a new additional questions... Is it a good practice to have lot of QHashs for various dynamic widgets.. will it impact performance in long run.. do i need to keep checking if those Qhash maps are being used..and if not should i erase them to free up memory spaces due to those unused QHash memory pointers
@@Mdzab2000 I like to use hash maps to quickly have access to different items. Ideally, you want to remove items from the map as you stop using them. For me, when I use them, when I create the item (say, a widget in your case), I add it to the hash map. Then, once I no longer need it, I remove it as part of its deletion (right before it). There is no benefit to keep unused data any more. Not sure what you are implementing, but it's how I generally use the QHash. Create, insert, use, remove, delete. Keep it clean! :D
@@VelcodeCS i added set of hboxlayout with number of combobox to a vhbox layout. i have two seperate buttons for add and delete items. i am able to add the hboxlayout everytime when i click add. But i am unable to delete the item. please can you help me.
What is the difference between a frame and a layout? They seem the same to me.
Frames have visual properties (background color, margins, etc.). Layouts do not. Frames also have a main layout within them to organize the UI elements within them (which is off by default). I hope this helps.
bro, you literally saved my ass again haha
Hi there,
somehow my qobject_cast() seems not to be worked and it makes the application crashed.
why is it happenning I don't know. If I comment out the line then it works.
void MainWindow::onAddWidget()
{
QVBoxLayout *layout = qobject_cast(ui->frame->layout());
QString buttonText = tr("Button #%1").arg(layout->count());
QPushButton* button = new QPushButton("buttonText",ui->frame);
layout->insertWidget(0,button);
}
I am using qt 6.4.0 mingw 64
Thanks in advance💕💕
So it's probably one of two possible issues, your ui frame's layout is not a QVBoxLayout or your ui object is null. Makes sure your widget is properly set up and you're using the right classes.
comment for support . You really help . I know that i can find in the net but its too faster.
can you do this on python?
Bro can you tell me how to do this on PyQt5/Pyside 2?
I would, but I myself have never touched PyQt 😬
thank you very very much !! cute sheep btw 😄
Thank you 😅
Great, good job guy
is this qt 5 or 6 ?
Should work for both
Is this posible to do the same with python?
🤔 I myself have never used Qt with Python, but I don't imagine the API being different. Would have to give it a try.
@@VelcodeCS Could you please show this exact thing in python? I have been struggling with it for months :' Thank you !
@@rryann088 That would be an interesting video to make! Although I myself haven't messed around with Qt and Python.
@@VelcodeCS Thank you so much for your response! ❤️ I would like to request you to make it, please :) And it is truly highly appreciated from my side - sure please take your time, i know you got this 😊 tbh I will be waiting for it 👍
QPushButton gives allocation error
Any way you can share your setup to see what the problem may be? I've been doing this in my projects with no issue.
you may need to add #include on your .h code. idk why but it worked :)
thank you very much
Can you show us how to make a flowchart application please. I'd pay for it. Patreon or whatever you like. thanks.
An application to make flowcharts?
@@VelcodeCS just like the diagram scene example in the QT Creator example. thank you
Do you have any specification of the software you're trying to implement?
@@VelcodeCS It's exactly like the (Diagram Scene Example) from the examples that come with Qt Creator.
how to delete all buttons, after one click
You can follow the same logic, just loop through all the things you want to delete.
Can you show us how to make it in python?
Not a bad idea! I've been wanting to work on some more Qt videos but have been busy. Fortunately the semester is over, so I should have some time to make some more!
Thank you very much