Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QToolBox remove widget
Forum Updated to NodeBB v4.3 + New Features

QToolBox remove widget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    broadpeak
    wrote on last edited by
    #1

    I'd like to remove a widget (not an item!!!) from my QToolBox.
    How can I solve this?
    I'd like to remove the widget what I added in this way: "layout->addWidget(button);"

    Relevant code snippet:
    @
    QMultiMap<int, int> multiMap;
    ....
    toolBox = new QToolBox(this);
    QVBoxLayout* layout;
    QWidget* widget;
    QPushButton* button;

    QSet<int> keys = QSet<int>::fromList(multiMap.keys());
    foreach( int key, keys )
    {
        layout = new QVBoxLayout();
        widget = new QWidget(this);
    
        QList<int> list = multiMap.values(key);
    
        foreach( int value, list)
        {
            QString s = QString("Camera %1").arg(QString::number(value));
            button = new QPushButton(QIcon(":/images/camera_icon.png"), s, this);
            button->setFlat(true);
            layout->addWidget(button);
        }
    
        layout->addStretch();
        widget->setLayout(layout);
        QString s = QString("Camera Group %1").arg(QString::number(key));
        toolBox->addItem(widget, QIcon(":/images/camera_groups_icon.png"), s);
    }
    

    @

    1 Reply Last reply
    0
    • I Offline
      I Offline
      issam
      wrote on last edited by
      #2

      What you mean by "remove the widget" ?
      If you mean hiding then showing the widget (remove from the layout) you have two ways :

      Remove the widget from the layout by calling QLayou::removeWidget().

      Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.

      http://www.iissam.com/

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        [quote author="issam" date="1349778696"]What you mean by "remove the widget" ?
        If you mean hiding then showing the widget (remove from the layout) you have two ways :

        Remove the widget from the layout by calling QLayou::removeWidget().

        Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.

        [/quote]

        I'd like to remove the button(s). But when I clicked on a button, I get wrong widget. I cannot cast it to qpushbutton.
        I cannot retrieve the current (selected) button (to remove)...

        1 Reply Last reply
        0
        • I Offline
          I Offline
          issam
          wrote on last edited by
          #4

          bq. broadpeak : I cannot retrieve the current (selected) button (to remove)…

          In this case I suggest to use QToolButton with QButtonGroup you will find it easiest :

          bq. QButtonGroup class provides a container to organize groups of button widgets.

          QButtonGroup provides three methods (signals) that allow you to determine the clicked button by returning its id !!

          and make this small change in your code please:
          @widget = new QWidget(toolBox);@
          or simply :
          @widget = new QWidget;@
          The widget's parent is not required because you will call QToolBox::addItem() !

          http://www.iissam.com/

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved