I subclass a QTableWidget class and wanted to display in QTabWidget, something like this:
class Mainwindow:
_tabWidget->addTab(doc, QFileInfo(doc->fileName()).fileName());
class doc:
_tableWidget = new QTableWidget(row, column);
I can debug that "doc" is not NULL.
_tableWidget have values in rows and cells.
But all I can see on my application is the display of tab with correct label,
there are no rows and columns drawn.
I created the _tabWidget programmatically.
What are the reasons why the content of "doc" were not displayed?
Thanks in advance.
I tried to access the QTableWidget object of custom class from the Mainwindow class using a getter function (doc->table()):
_tabWidget->addTab(doc->table(), QFileInfo(doc->fileName()).fileName());
The rows and columns are now displayed.
Is it really the way to do it?
What you are doing in the little piece of code showing is creating a QTabWidget and adding a tab with a QWidget (base class of Doc) object. In your edit (that works), you are no longer adding the QWidget (doc), but adding a QTableWidget object (doc->table()) directly, which works.
I thus can only conclude that you are not setting a layout for QWidget and thus not putting the QTableWidget in the layout.
Related
I'm stuck. With QTableView + QStandartItemModel + QSortFilterProxyModel I can only add 1 QLineEdit for 1 specific column line_edit.textChanged.connect(filter_model.setFilterRegExp). Moreover I can't figure out how to add widget item to QTableView but only to QTableWidget (which i can't use because of filter?). I may give up the idea of adding widget and just make my whole row open another dialog on double click.But still I don't understand how to filter multiple columns at the same time. Thanks in advance
Moreover I can't figure out how to add widget item to QTableView
You need use QtGui.QItemDelegate for such thing. Have a look at this nice code snippet (not mine). And please read Qt manual about QItemDelegate and Model View Delegate pattern.
How can I save the QTreeWidget column order ?
I know it can be done via QTreeView from this post
HowTo make restoreState() and saveState() work correctlly to QTableView class?
but I don't see how I can do it with QTreeWidget.
Any suggestions ?
A QTreeWidget is a QTreeView (it inherits it), so any function you can call on a QTreeView, you can also call on a QTreeWidget.
You can get the (only) header from a QTreeView (and therefore also from a QTreeWidget) using its QTreeView::header() member function. For example:
QTreeWidget *treeWidget = new QTreeWidget(this);
QByteArray saved = treeWidget->header()->saveState();
I have designed a QWidget based QtDesigner ui form. Lets call it Form1. I added few pushbuttons and labels in it. Now I designed another QWidget based qt ui designer form.Lets call it Form2. I have a QFrame in Form 2 in which I would like to load Form1.
I did some reading and I found that I could right click on QFrame and choose promote to. I put the base class as QFrame. Promoted class name as Form1. Header file as form1.h.
I get errors now saying:
Form1 has no member named 'setFrameShape'
Form1 has no member named 'setFrameShadow'
I changed the base class as QWidget. And it still did not load the Form1 in the QFrame of Form2
Any help is appreciated.
EDIT:
I used base class as QFrame and
I commented out following lines in the ui_form2.h and it worked frame->setFrameShape() and frame->setFrameShadow() and it worked.
If there is better way to do it kindly let me know
Promoting a widget in designer is just a way of saying "I know this looks like <Standard Widget>, but when you generate code I actually want you to create a <More Specialized Widget> here instead." The widget you promote (and the base class for promotion) need to be of a type that is an ancestor of the type you are promoting to.
In your specific case, the base for your promoted widget should be QWidget (instead of QFrame), because that is the type of Form1. You should put a plain QWidget inside your frame and promote that widget instead of the frame.
I'm new to Qt programming and I am developing a drawing application. I have a class MyWidget which has a member QGraphicsView. MyWidget is a member of another class MainWidget (which has other widgets as well and all of them are in a layout).MainWidget is the central widget of my subclass of QMainWindow.
I have created functions to scale the view with the mouse wheel event and a function to drag the scene around.
The problem is - I want to set the Scene's size to be fixed, and to be 3 times the size of the view, but since the view is managed by a layout in order to take as much space as possible I can't get the view's size?
Any help appreciated.
the size property will give you the current size of your widget:
http://qt-project.org/doc/qt-4.8/qwidget.html#size-prop
Alternatively, you could subclass QGraphicsView and re-implement the resizeEvent:
http://qt-project.org/doc/qt-4.8/qwidget.html#resizeEvent
For a full example, have a look into:
http://qt-project.org/doc/qt-4.8/widgets-scribble.html
You can definitely get the view's size. There are two ways to go about it:
Attach an event filter object to your view: myView->installEventFilter(filterObject). The filterObject's eventFilter method will be invoked for all events reaching your view, including resize events.
Use a custom view class and reimplement resizeEvent. This method gets called each time the widget is resized. Do note that designer allows you to add custom classes without having to write plugins.
I am not able to remove a particular widget from a cell in a qgridlayout. I tried several codes found in internet... but i failed!! the way how i did the work was, first i created a qwidget class containing button,qpixmap,qplaintextedit. i then created an object of this class and it was set dynamically on the QGridLayout. the layout was then set on the current widget using this pointer. I am able to addwidgets on the gridlayout, but not able to delete it.. i want to delete the whole widget i created only if the pixmap is null!!! Do anyone knows a suitable remedy for this problem??
To remove a widget without deleting it, call
void QLayout::removeWidget(QWidget*)
To remove and delete a widget, just delete it.