[SOLVED] Make all toolbar buttons same clickable size



  • Hello,

    I have a vertical toolbar that I have placed buttons with images in. I have tried making the button sizes all the same, however when I scroll over them, the clickable size (based on the scrolled over highlighted area) of the button seems to be different for all of them. It seems to be conforming to the size of the image placed in the button. The code I used for two of the buttons is as follows:

    @ /Define size of icons/
    QSize toolBarButtonSize;
    toolBarButtonSize.setHeight(35);
    toolBarButtonSize.setWidth(35);

    /*Create buttons and display icon/text for each*/
    onButton = new QToolButton(toolBar);
    onButton->setIcon(QIcon("C:/on.png"));
    onButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    onButton->setIconSize(toolBarButtonSize);
    onButton->setText("On");
    powerState = 0;
    
    runButton = new QToolButton(toolBar);
    runButton->setIcon(QIcon("C:/arrow_green.png"));
    runButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    runButton->setIconSize(toolBarButtonSize);
    runButton->setText("Run");@
    

    It doesn't look to professional like this so I want to know how to make the actual clickable button the same size so that everything is uniform...

    Thanks!



  • when you say you tried to make the icons the same size, are they the same size ?
    you could try
    @onButton->setMaximumSize(toolBarButtonSize);
    runButton->setMaximumSize(toolBarButtonSize);@

    but if the images aren't the same size you might get some clipping.



  • [quote author="clogwog" date="1375195696"]when you say you tried to make the icons the same size, are they the same size ?
    you could try
    @onButton->setMaximumSize(toolBarButtonSize);
    runButton->setMaximumSize(toolBarButtonSize);@

    but if the images aren't the same size you might get some clipping.[/quote]

    The icons are the same size, but I guess because the images are different sizes, when you scroll over them the highlighted region just shows the image size. I want to stretch this to be the entire button size without changing the image size.



  • clogwog put me in the right direction. I solved it using:

    @ onButton->setMinimumSize(toolBarButtonSize);
    runButton->setMinimumSize(toolBarButtonSize);@

    Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.