I placed into the mainwindow QTabWidget with some content. But mainwindow is overloaded, so I decided to put the logic of the elements in each tab into a separate class, i.e. 6 more files appears in my project:
MyTabWidget1.h
MyTabWidget1.cpp
MyTabWidget1.ui
MyTabWidget2.h
MyTabWidget2.cpp
MyTabWidget2.ui
Now I want the contents of the tabs to appear in the main window's Tab Widget. How can I do it?
You have 2 options to compose widgets:
1) In Designer mode of Creator using the promote widget functionality. Add the pages into the tab-widget in designer, make sure you select each page individually not the QTabWidget (you can do that in the object browser, each page will be a child of the QTabWidget) select Promote to... in the context menu for each individual page and enter the corresponding class name and header filenames in the dialog that opens.
2) using C++ code you can access the tab widget inside main window class and use addTab
//in the constructor of mainwindow you can do something like this:
ui->TABWIDGET->addTab(new MyTabWidget1(), "First tab");
ui->TABWIDGET->addTab(new MyTabWidget2(), "Second tab");
//replace TABWIDGET with the corresponding name you used for your tab widget in the mainwindow.ui
Related
I am trying to promote the top level QWidget into a derived MyWidget class using the "promote to" menu in Qt Designer.
For that, i have defined the promotion with the "promoted widgets.." menu.
I have also add a child QWidget (in violet) to the top level QWidget and i was able to promote into it into MyWidget using the "promote to" option, that appear after a right click in the object inspector. (as shown in the picture)
But for the top level QWidget, the right click don't give access to the "promote to" menu and i have the same problem with a QFrame.
Is it possible to do that with Qt Designer ?
Thank you.
No, you can't promote top Widget in Designer. But you can do it manually. Simply open ui file in text editor and make necessary changes to the top level widget. Which changes you will need you can see in your child widget defenition. Just copypaste needed fields and values.
Qt 5.5 has a virtual method to define a custom widget for editing mode:
QWidget *createEditor(QWidget *parent,const QStyleOptionViewItem & option ,const QModelIndex & index ) const
But how to use a custom widget to override the "view" mode?
I saw "stars rating" delegate example where paint method is used but that's not what I need. I need to show a custom widget that contains other standard widgets inside it and use it in a view mode of QTableView or QListView. No need to get mess with painting pointers and figures - just show a custom widget (that has .ui file) and contains other standard widgets with their behaviour.
For example:
There is a download manager application that can show downloads either as a table or list view. QListView with a list of downloads. Each download has URL, Title, TotalSize, DownloadedSize, ProgressBar, Pause button, Remove button, Resume button. All of those can be columns in a table (QTableView) or composed similar to HTML's DIV in one cell (QListView widget)
How to achieve it? Is there anything like QWidget *createViewer(... ?
QtWidgets are used no QML.
For static content you can use QAbstractItemView::setIndexWidget.
For dynamic content the only option is to implement paint method in you delegate class.
I think i'm having a fairly basic Qt problem, but i can't figure it out:
I have a QMainWindow which holds a QStackedWidget. All page widgets in there are seperate classes derived from QWidget.
So:
QMainWindow implements QStacked Window in one class.
All other pages inside the stacked widget are added classes and all have there own .ui filled with buttons and lists trough the Designer.
For navigating to different pages, inside the Mainwindow i have access to: ui.stackedWidget->setCurrentIndex(2);
It seems i don't have access to ui.stackedWidget on another page inside the stacked widget? I have no access to the ui.stackedWidget because Ui is a private member in the mainwindow class. (auto generated by Qt - using VS addon for adding QT4 classes)
I would like to know, how can i jump to another page in the stacked widget, when clicking on a button that belongs to another page inside this widget?
Note:
All pages are added to the StackedWidget in mainWIndow's constructor:
ui.stackedWidget->addWidget(page1Widget);
ui.stackedWidget->addWidget(page2Widget);
// etc..
Example of a button click signal-slot inside page1Widget:
connect(ui.btnViewData, SIGNAL(clicked()), this, SLOT(viewData()));
::viewData()
{
// navigate to another page here.
// note: ui.stackedWidget->setCurrentIndex(3); is not accessible here!
}
I believe that putting your connect() and viewData() functions within your QMainWindow object will solve your problem, since the main window can have access to both the signals emited by the child widgets and the QStackedWidget items.
You might need to write a Ui getter for each of your page, and then do something like
connect(page1Widget->getUi().btnViewData, SIGNAL(clicked()), this, SLOT(viewData)));
hope it helps,
cheers
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.
I have a Main window build with Qt Designer and I also have a widget built with Qt designer (both in a separate ui file). How can I instantiate my widget into my mainwindow at runtime?
The easiest way (using Designer) is to open your main window, drag a QWidget into it, and position/name the QWidget like you would your custom widget. Once that is done, right-click on the QWidget, and select Promote to.... A dialog will show up with the widgets it can be promoted to. At the bottom of that dialog, you can add a new widget for promotion. Type in the class name and include file information, and add that widget. Then select the entry in the list, and click the Promote button.
At the end of this process, you should be able to recompile, and your custom widget will be where you placed it in the main window.
Can't you use QMainWindow::setCentralWidget function?