Is there any solution to embed a QLabel in QStatusBar using Qt Designer?
I don't believe so. It's fairly simple to add one programmatically, though.
If you're just wanting to show a message, you could use: statusBar()->showMessage(tr("Message Here"));, or alternatively if you really needed a QLabel on the status bar, you could do something along the lines of:
QLabel *label = new QLabel("Message");
statusBar()->addWidget(label);
label would become a child of statusBar(), and appear in the first empty spot from the bottom left (addPermanentWidget(label) would add it to the first empty spot from the bottom right). If you place QLabel label in the classes header (or other var name), you'd be able to access the variable directly later (removing the initial QLabel type from the first line, of course).
It is not possible with Qt Designer. I resolve it by creating label a in Qt Designer and later in constructor of my MainWindows add this line:
Ui::"class name of my MainWindows"::"name of statusBar Object"->addWidget("Object Name of Label");
In my application, the class name of mainwindows is MainWindowsForm, the status bar is named statusBar and the label is named informationLabel. Then I have:
Ui::MainWindowsForm::statusBar->addWidget(informationLabel);
It's not possible even if you would manually edit UI file.
Related
I'm new to QT. when I create a qwidget such as a qlabel, programmatically, it never shows in my main window or anywhere else. But when I create one using the IDE it works fine. What am I missing ?
By default, widgets are set to invisible, therefore, you need to call .show() to make a widget visible. For example,
QLabel *label = new QLabel("click");
label->show();
Using the debugger I noticed that my QLabel had the wrong parent. Setting the parent correctly cured all of my problems. The other answers to my question were relevant too.
I have a class myTreeView which is a subclass of QTreeView, which I am using in other widget and doing layout manually. now I want to include myTreeView in the new widget using designer so that I can avoid layout code. any suggestions/reference, how to do this ?
Place a QTreeView into your layout in Qt Designer. Right click the QTreeView, click Promote to... add a New Promoted Class definition using the form at the bottom of the dialog.
i.e. specify the base class of your derived class as QTreeView, give the widget a name, and specify where Qt Design can find the header file for your derived class.
That should allow you, at a minimum, to place your widget on the form as you lay it out. It will most likely show up as a grey empty box (much like a QWidget) on the layout however when you compile and build a project using your .ui file your widget will appear.
On this site
there is a picture with two "tab-systems".
I would like to have the second one, which is described as "A truncated tab bar shown in the Plastique widget style." There you have arrows, which allow you to slide through the tabs.
I have implented a "tab-system" which looks like this:
QTabWidget *tabWidget = new QTabWidget();
tabWidget->addTab(ToolGroupBox(),"Toolbox");
tabWidget->addTab(CameraGroupBox(),"Camera");
...
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(tabWidget);
As I understand it is possible to create the truncated tabs if I use the tabRect-function of the QTabBar-class. I have tried several things but unfortunately its not working.
You want the usesScrollButtons property of the QTabBar. You can access the QTabBar of your QTabWidget via the tabBar method.
You don't need to get involved with tabRect at all. The documentation just before the picture of the two tab systems is not directly related to it. The figure is just showing you two possible tab styles.
when i add the widget to the main window, by default the action menu item will be present,
how to remove that?
menuBar()->setVisible(false);
verAction = new QAction(tr("&Version"),this);
menuBar()->addAction(verAction);
connect(verAction, SIGNAL(triggered()),this, SLOT(displayVersion()));
displayAction = new QAction(tr("&Display"),this);
menuBar()->addAction(displayAction);
connect(displayAction, SIGNAL(triggered()),this, SLOT(displayMessage()));
exitAction = new QAction(tr("&Exit"),this);
menuBar()->addAction(exitAction);
connect(exitAction, SIGNAL(triggered()),this, SLOT(close()));
Thanks
If you want to hide an QAction and display it when you need it, you can use the setVisible function.
If you want to remove the menu bar from the QMainWindow, you can use the QT_NO_MENUBAR preprocessor to remove all uses of a QMenuBar. If you are not using facilities provided by QMainWindow, maybe you can use a simple QWidget as main window in your application.
[Edit]
If you want to hide QActions at runtime, you will find them as member of the QMainWindow's UI. For example if you have a QAction named actionTest, you will access it like that: this->ui->actionTest->setVisible(false);
I know what you mean... you want to HIDE the DEFAULT CONTEXT MENU "Actions"....
You can do this in the Design section (not in code).
Then you see your Object-Stack on the right side like
MainWindow QMainWindow
centralWidget QWidget
webView QWebView
Now go to the property editor below...search for "contextMenuPolicy" and change it from "DefaultContextMenu" to "NoContextMenu" for every component if necessairy.
In order to remove the default context menu with the label "Actions" the following code may be used:
// Remove context menu from the all widgets.
QWidgetList widgets = QApplication::allWidgets();
QWidget* w=0;
foreach(w,widgets) {
w->setContextMenuPolicy(Qt::NoContextMenu);
}
Essentially, the same as the Joel's answer, but the code version :)
(Code taken from QFriendFeed sample from forum.nokia.com)
In my QT application I use a QTabWidget for the base navigation. This QTabWidget I setup in the ui. In some of the tabs of the QTabWidget I need to have QStackedWidget to be able to "drill down in the view".
I tried adding the QStackedWidget inside the ui also but it automatically adds a page to the stack. I want to add the pages for the QStackedWidget in code instead. If I in the code try to do this the stackedWidget already have a standard page so myWidget will be the second in the stack.
MyWidget *myWidget = new MyWidget(ui.stackedWidget);
ui.stackedWidget->addWidget(myWidget);
What is the best and easiest way to setup a QStackedWidget inside QTabWidget tab?
How about:
QTabWidget *myTabWidget = new QTabWidget(this);
QStackedWidget *myStackedWidget = new QStackedWidget(myTabWidget);
myTabWidget->addTab(myStackedWidget, "Stacked Widget");
Also you can remove all existing stack pages in Qt's Designer/Creator. Just right-click on the stacked widget and remove all existing pages. Then you can add the needed pages in the code using addWidget().
I'd say - create it in ui, just like you do (this way it's easier to layout/position, add other widgets on the tab later, etc), but simply remove all existing pages (added by designer) from code and add your new ones.
Actually Designer from Qt 4.6 allows to delete all pages from stacked widget - you need to right click, go to submenu "Page X of Y", and choose Delete. Repeat until all pages are gone :)
Maybe this got added to the Designer just recently, so you may still need to remove them from the code if you have an earlier version of Qt.
Speaking of keeping stuff inside ui against keeping it in code i'd vote for "as much in UI-file as possible" :)