Qt - How to override a widget?
I've created a form using the Qt designer which includes a QToolButton.
I can turn it usingui->favouriteToolButton
.
I used the designer because it's much more simple then code all the gui.
Problem is开发者_StackOverflow中文版 that specifically for this ToolButton
i want to code by creating its own class:
class FavouriteMenu : public QToolButton
{
Q_OBJECT
public:
explicit FavouriteMenu(QWidget *parent = 0);
//~FavouriteMenu();
private:
QMenu *menu; //MENU
QAction *addToBookmarkAct;
QAction *editBookmarkAct;
...
I want to be able to override ui->favouriteToolButton
with a new instance of FavouriteMenu.
How can i do it?
- Right click on the button in designer and select "Promote To..."
- Under Promoted class name enter "FavouriteMenu"
- Under Header File enter the filename of the .h file
- Click "Add"
- Click "Promote"
精彩评论