Results 1 to 4 of 4

Thread: how to create folders and sub folders in qt

  1. #1
    Join Date
    Jul 2013
    Posts
    25
    Qt products
    Qt5
    Platforms
    Windows

    Default how to create folders and sub folders in qt

    In my application ,I have to create push buttons dynamically. When I clicked a particular button,a groupbox will appear.
    When we right click ,a menu will appear and we can select "new folder" option. Then there should appear a push button. When ever the user clicks the right button and select new folder, a new push button should appear in the group box and all the buttons in the groupbox shold be arranged in a row by column manner.
    ALL your suggestions are appreciated.Thanks in advance.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to create folders and sub folders in qt

    All that description is fine but what is your question / problem.

  3. #3
    Join Date
    Jul 2013
    Posts
    25
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create folders and sub folders in qt

    Actually ,I need the code for that. I already tried the following code.
    But , it create buttons in different places, not in tha particular lay out and only 2 buttons were created. In the 1st button the size is not followed. Can u suggest any idea. Thanks in advance.


    Qt Code:
    1. bool MainWindow::eventFilter(QObject *object, QEvent *event)
    2. {
    3. if(ui->groupBox4==object)
    4. {
    5. if(event->type() == QEvent::ContextMenu)
    6. {
    7. // QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
    8. QMenu *menu = new QMenu(this);
    9.  
    10. QAction* myAction1=new QAction(tr("New folder"), this);
    11. QAction* myAction2=new QAction(tr("Delete "), this);
    12. QAction* myAction3=new QAction(tr("Rename"), this);
    13. //Connect the actions to slots in your main window
    14. connect(myAction1, SIGNAL(triggered()), this, SLOT(Function1()));
    15. connect(myAction2, SIGNAL(triggered()), this, SLOT(Function2()));
    16. connect(myAction3, SIGNAL(triggered()), this, SLOT(Function3()));
    17. //Add the actions to the menubar (or a menu)
    18. menu->addAction(myAction1);
    19. menu->addAction(myAction2);
    20. menu->addAction(myAction3);
    21. menu->exec(QCursor::pos());
    22.  
    23. return false;
    24. }
    25. }
    26. }
    27. void MainWindow::Function1()
    28. {
    29. QPushButton *pb=new QPushButton("button",this);
    30. pb->resize(191,111);
    31. QGridLayout *vbox = new QGridLayout;
    32. vbox->addWidget(pb);
    33. pb->move(370,150);
    34. pb->show();
    35. // vbox->addStretch(i);
    36. // ui->groupBox4->setLayout(vbox);
    37.  
    38. }
    39. void MainWindow::Function2()
    40. {
    41. qDebug()<<"delete";
    42. }
    43. void MainWindow::Function3()
    44. {
    45. qDebug()<<"Rename";
    46. }
    To copy to clipboard, switch view to plain text mode 
    Can u suggest the code for how to delete the dynamically created button and how to rename it, whenever we want.
    Last edited by wysota; 30th August 2013 at 06:48. Reason: missing [code] tags

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to create folders and sub folders in qt

    If you want the new QPushButton to go into an existing layout then you should insert the widget into that existing layout. At the moment you are creating a new layout each time Function1 is called and that layout is unrelated to the existing layouts.

    You also need to understand that the layout drives the size and position of the button, not the other way around i.e. calling resize() or move() on a widget in a layout is usually pointless.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. How to select folders from QFileDialog???
    By IndikaU in forum Newbie
    Replies: 4
    Last Post: 30th September 2011, 09:19
  2. Qt Creator Project folders
    By Quasimojo in forum Qt Tools
    Replies: 2
    Last Post: 13th January 2011, 00:24
  3. move folders in QDirModel
    By janus in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2009, 18:38
  4. dynamically create folders with QT
    By eleanor in forum Newbie
    Replies: 3
    Last Post: 13th March 2007, 11:40
  5. Creating, deleting folders with C++?
    By pir in forum General Programming
    Replies: 7
    Last Post: 1st August 2006, 11:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.