1

in my GUI program I have a QToolBar at the bottom of my mainwindow which contains a number of QAction buttons for opening various dialogs.

Now, I have adjusted the size (i.e. width) of icons of the QToolBar through the QTCreator interface size policy. The size of icons are set manually in such a way that they occupy the entire width of the QToolBar.

enter image description here

Now, due to some required functionality of my program, I need to disable / hide one QAction button (i.e. the Icon). But when I hide that;

if(myconditions = true)   //when my conditions to hide the button are met
{
    ui->myaction->setVisible(false)
}

The rest of the QAction icons shift accordingly and a blank space (with the width same to the hidden icon) is left in the toolbar.

Can I adjust the size (i.e. width) of icons of the QToolBar through coding so that they occupy the entire space even if one or some gets hidden ? I couldnt find such options in the QTCreator GUI - icon size options.

From the documentation it seems it can be solved using iconSize but I dont know how to use it in code.

  • 1
    so you want to stretch the remaining icons width to the available size right ? – RicoRicochet Jan 27 '15 at 11:20
  • yes, indeed that is what i need to do. the documentations are very good but i am new to qt and the info is a little sketchy to me. – OneDoesNotSimplyProgramCodes Jan 27 '15 at 11:35
  • 1
    well, i have a hit and trial kinda solution for you, it is not much elegant and doesnt make the width of remaining icons stretching automatically, you have to pass the optimum width after stretching manually. toolbar->setIconSize(QSize(desired_width,height) from your screenshot you can keep the height as 38 only. – RicoRicochet Jan 27 '15 at 11:41
  • it is a cumbersome process and time consuming, but if you have to make adjustments for only one or two buttons its definitely worth a shot.. – RicoRicochet Jan 27 '15 at 11:41
  • got right on the third try :D :D :D with width 72.. indeed time consuming but for now its working.. thnx – OneDoesNotSimplyProgramCodes Jan 27 '15 at 11:49
  • okay, its a bad / improper process, but your ques has also made me think, looking for a proper way to achieve the same as well.. – RicoRicochet Jan 27 '15 at 11:58

0 Answers0