How to add a button onto toolbar in Qt Designer

Like other components of Qt, Qt Designer also proves the whole Qt stuff is developed by some amateurs. When you create a Qt widget project in Qt Creator, you are creating a QMainWindow GUI by default. When you click Forms/mainwindow.ui under your project, you are brought to the Qt Designer UI:

 

Where is the toolbar of the QMainWindow? Is it where the “Type Here” lies on? No, that is the location of menu bar. The toolbar is under the menu bar. It is a narrow strip and hardly seen. Did you see a toolbar like that in the real world? You finally got to know where the toolbar is. Next, you may want to add a button to the toolbar. You may try to drag a Push Button from the left widget box onto the narrow toolbar strip. But you’ll soon be disappointed because Qt Designer does not allow to put a button on the menu bar. What a stupid designer. Now I think 90% of you won’t figure out how to add a button onto the toolbar by yourself. The you begin to search google for how to put a button on toolbar in Qt Designer. You will get this post. The steps to place a button on the toolbar is rather complex and not straight-forward. Here is how you can add a toolbar button:

First, you should go to the Action Editor(right below the main design window). Click the first button(New) of Action Editor to create a new action. You can type the text on the button now.

Second, you need to drag the action to the toolbar:

Third, you need to right-click on the action and click “Go to slot” to edit the on-click function, i.e., the event handler of the button.

Now you should be able to add a toolbar button and know how to write its event handler.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply