Create TAB and create textboxes that take data in the TAB-page - class

I am working in PyQt. The existing code (extremely long and sources almost all the org.'s s/w) has sections which is responsible for creating tabs and textboxes. But, being a newbie to PyQt, I am not clear on how it all works. For my part, I need to do the following:
(1) Create a TAB titled 'xyz' within the row of all the other tabs.
(2) Create 6 textboxes with individual labels in the page displyed by the created TAB where the user can enter data and save it.
These are the two immediate problems I have to deal with now. Later,
The data entered in the textboxes will replace the data in bar-graphs (in another window) as soon as the data in the textboxes is entered and saved. This is to be done afterwards but first I need to solve the 2 issues listed above. The imports are all there in the (longish) code and I have to insert my new code within that code - perhaps by creating a new class. Can you help? Thanks. And, please let me know if you need any information to work on this.
EDIT::::::::::: Have inserted the image below. As you can see, at the top of the left pane, there are multiple tabs in a row (all made in PyQt). I need to create a tab like the last one (here, titled-Incentives) with a blank page like the one shown below the tab. Within the page, I need to create 2 sets of textboxes, 3 textboxes in each set with labels for the set(s) and the individual textboxes. Data entered in the boxes will be integers(20) and the data will then go on to populate/update a dynamic stacked bar graph. At this point, I want to ask another question. When the data updates the graph, should it be first saved in the DB (the DB which is primarily responsible for the initial figures in the graph) and then routed to the graph or should the data update the graph directly, bypassing the DB and if so, won't the graph revert to its earlier values and forget the data from the textboxes once it is reset. Thank you.

OK. Here you have a code that you can use as a starting point for your own development. It creates a QTabWidget with two tabs. The "Tab 1" tab contains a vertical layout with two groupboxes. Groupboxes contain labels and textboxes arranged in a grid. The other tab is empty.
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyMainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
# Create the tabbed widget
self.central = QTabWidget(self)
self.setCentralWidget(self.central)
# Create a new tab
self.tab1 = QWidget()
# Tab has a vertical layout
self.vbox = QVBoxLayout(self.tab1)
# Tab children: two groups containing a grid of labels and textboxes
self.group1 = QGroupBox("Group 1")
self.textBox1 = QLineEdit(self.group1)
self.textBox2 = QLineEdit(self.group1)
self.fillGroup(self.group1, self.textBox1, self.textBox2)
self.group2 = QGroupBox("Group 2")
self.textBox3 = QLineEdit(self.group2)
self.textBox4 = QLineEdit(self.group2)
self.fillGroup(self.group2, self.textBox3, self.textBox4)
# Add tab children to the tab layout
self.vbox.addWidget(self.group1)
self.vbox.addWidget(self.group2)
# Append tab to the tabbed widget
self.central.addTab(self.tab1, "Tab 1")
# Create a new tab and append it to the tabbed widget
self.tab2 = QWidget()
self.central.addTab(self.tab2, "Tab 2")
def fillGroup(self, group, box1, box2) :
"""Arrange the groupbox content in a grid layout"""
grid = QGridLayout(group)
label1 = QLabel("Input 1:", group)
grid.addWidget(label1, 0, 0)
grid.addWidget(box1, 0, 1)
label2 = QLabel("Input 2:", self.group1)
grid.addWidget(label2, 1, 0)
grid.addWidget(box2, 1, 1)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
ui = MyMainWindow()
ui.show()
sys.exit(app.exec_())
Please notice that for my convenience I've used a QMainWindow as a parent for the tabbed widget. Obiously you can use other widgets as parent if you need it.
Hope it helps.

Related

How to display sheet(s) on dashboard using navigation?

I'm creating a dashboard on Tableau and I want to have a set of navigation buttons that correspond with the sheets I've created. When a button is clicked I want the corresponding sheet to be displayed on my dashboard instead of navigating to the sheet itself. I want all of the sheets to be displayed in the same place on my dashboard. For example, If button 1 is clicked I want sheet 1 to be displayed on my dashboard. If button 2 is clicked I want sheet 2 to be displayed on the dashboard in the same place. I'm new to Tableau and would appreciate any help with this!
The easiest way to achieve this is using parameters.
As a first step you need to creat a parameter with a list of values matching the number of worksheet, like: Worksheet 1, Worksheet 2, etc...
Then you have to create N calculated fields in order to check if the "actual" worksheet is the one "selected in the parameter", using "ok" and "ko" as results for your filters, keeping just "ok".
The formula could be something like this (assuming you're doing the CF for the 1st worksheet, and the other ones differ just for the value):
if parameter = 'Worksheet 1' then 'ok' else 'ko' end
Doing so, all you're worksheets will present data just one at a time because all of them but the one matching the valus in parameter will be blank.
Then you can create your dashboard putting a vertical (horizontal as well if you like) container in it which will be the the "place" where you'll drag all your worksheets.
Be sure to NOT modify the spacing and height of them; just le tableau handle that for you, otherwise the trick won't work.
Once you're finished you will end up having a container with N worsheets in it, with just one of them dysplayed at once.
Once you'll become familiar with parametr actions, you will no longer need to have the parameter displayed on the dashboard (show parameter) because using a worksheet connected to the parameter values you will be able to decide the value of the parameter via click on your additional worksheet acting like a series of button (woeksheet 1, worksheet 2, etc...)

How to get focus on a subform in LibreOffice Base using tab

The question and answer LibreOffice Base; Tab order from mainform to subform almost solve the issue I have, but not completely.
I have a table mytable (id, name, textfield). I'm displaying id and name in a form with a table layout (table control). I've added the column textfield from the same table as a subform with a text box control (the reason is that I want to enter text with newlines, while being able to navigate the records quickly in the main table). Here's what it looks like in design view:
I've added this Basic macro, based on the two answers linked above:
Sub Main
Dim root_doc As Object
Dim form_container, form_ctrlr As Object
Dim main_frm, sub_frm, tab_target As Object
root_doc = ThisComponent
form_container = root_doc.Drawpage.Forms
form_ctrlr = root_doc.getCurrentController()
main_frm = form_container.getByName("MainForm")
sub_frm = main_frm.getByName("SubForm")
tab_target = sub_frm.getByName("TextField")
form_ctrlr.getControl(tab_target).setFocus()
End Sub
Now, if I add the macro on the event When losing focus of the name column, I do get focus on the textbox when pressing Tab, but on the next row.
If I add the macro to the event On key press of the name column, I get what I want when pressing e.g. Space, but Tab or Enter only take me to the next row in the main form.
Is there a way to get this to work with Tab?
Options to solve this, from the answers over at ask.libreoffice.org:
Just use the standard Ctrl + Tab to switch focus.
Assign a macro to a custom key combination and use that. Not all combinations work, I settled on Shft + Enter.
And the macro (provided by user Ratslinger):
Sub Main
Dim oForm, oCtrlr, oField As Object
oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
oCtrlr = ThisComponent.getCurrentController()
oField = main_frm.getByName("TextField")
oCtrlr.getControl(oField).setFocus()
End Sub

how to hide and unhide authoerable tabs depending upon value selected from a drop down in CQ5

i am trying to create a footer component in CQ5, where i have 4 columns & all are autherable.
But we have to make no of columns autherable too i.e based on a value selected form a dropdown we have to open those many tabs for authoring those many columns only.
i have created a dropdown and have a maximum range of 6 columns. i know that i have to configure a listener for this purpose but don't know how . Requirement is like if i select 3 from the drop down then 3 tabs should come to author 3 columns
pls help me , i am middle of something very important.i need the solution very early too as i have to finish the job as soon as possible
I might be late for this by now but in case you still need it:
You need to add a listener node before closing your drop-down element:
<listeners
jcr:primaryType="nt:unstructured"
loadcontent="function(box){ //here you also need to handle the hide/unhide when the panel loads for the first time. Use this.getValue() to retrive the intial value }"
selectionchanged="function(box, value) {
for(var c=1;c<=value;c++){
this.findParentByType('tabpanel').unhideTabStripItem("tab"+c); // You need to handle the opposite with hideTabStripItem("tab"+c);
}
}"/>
Then on both "loadcontent" and "selectionchange" (these are events on your drop-down) grab the current selected value and use it to hide/unhide the tabs. In this case the tabs would be named "tab1", "tab2", etc, make sure you get the names right.
The ExtJS in the events is finding the "tabpanel" container for the whole dialog, and then hiding/unhiding based on name. You could also set to enable/disable using the methods ".enable()" and ".setDisabled(true)". Just make sure you get the reference to the tab first if you want to do this (something like ".getComponent(tabName).enable()").
I didn't test this specific code, I couldn't find my actual example from my code base but this should take you in the right direction.

Displaying forms using Tree in Qt

I'm building a Qt plugin with multiple forms. I have a main form which has a tree widget placed on the left of the form.
I want to add items to this tree, such that clicking on these items would load the corresponding form on the same form. But I want the tree widget to be active so that I can select any other form also.
I was able to display a form on the main form using the following code:
Form1 *myform;
myform=new Form1(this);
myform->show();
where Form1 is the class of the form i intend to display. However this, covers up the tree widget also. And I have to do a string comparison of the item in tree being clicked to display the appropriate form.
Can someone please help me with this as I'm very new to Qt programming.
Thanks
ixM has a good suggestion. The first step should definitely be to use layouts in your main window - separating the tree from the rest of the window - where you are going to put your form. I would suggest using a splitter, because then the user can resize the two halves. You can set the splitter as the main widget of your CentralWidget in your main window.
QSplitter splitter = new QSplitter(CentralWidget);
splitter->setOrientation(Qt::Horizontal);
splitter->setHandleWidth(3);
splitter->setChildrenCollapsible(false);
MyTree= new QTreeWidget(splitter);
splitter->addWidget(MyTree);
Then add your tree widget to the splitter, which will be on the left side.
The next step is to add a placeholder widget on the right side of your splitter. We are also going to add a layout inside that widget. This layout is very important we are going to use it later.
QWidget WidgetRightSide = new QWidget(splitter);
QVBoxLayout setupLayout= new QVBoxLayout(WidgetRightSide);
setupLayout->setSpacing(0);
setupLayout->setContentsMargins(0, 0, 0, 0);
Now, at this point, this is where my answer really differs from the previous answer. You could use a QStackedWidget. That is certainly an option. The problem with that is that you have to create and load all your forms at the beginning. That uses way more memory, and will take longer to start up. That's not so bad if you have 2-5 forms, but when we are talking about 20, 30 or more forms that's really ugly.
So what I would suggest instead, is that when the user selects something in the tree, we will remove the old form, and add the newly selected form at that point.
When the selected item in the tree changes this is now what we have to do.
First, remove all the stuff from the previously selection form.
QLayoutItem *_Item;
while ((_Item = setupLayout->takeAt(0)))
delete _Item;
Next, figure out what form to show next, and create it.
QWidget *ActiveSetupForm = NULL;
if ( I need to load form 1)
{
ActiveSetupForm = new YourNewForm( WidgetRightSide);
}
else ...
And lastly, add your new form to our layout.
if(ActiveSetupForm)
{
setupLayout->addWidget(pActiveSetupForm);
}
Just as a side note. Layouts are tricky to do by hand. I would strongly suggest that you look into using the QtDesigner when you are creating your forms. It makes life soooo much easier. If you would like to know more about it check out this link.
I don't exactly understand what you are trying to achieve but the bit of code you are showing suggests that you do not use the layouts provided by Qt.
If your goal is to be able to dynamically load a form depending on the item that was clicked in the tree, you could achieve that by having a layout (let's say QHBoxLayout) where you would insert your tree and a QStackedWidget in which you could "store" each form (by using addWidget()) and choose which one you want to display by calling setCurrentIndex().

Problem with tab index after closing one of the tabs in gwt

I am developing a application in GWT using the decorated tab panel. I have implemented a close option for the tabs. Now my problem is that when I close one tab and try to add some data in the other tab it is taking the wrong index.
For example: I have 4 tabs and close the third one. I open 4th tab and try to add something there, but its index is showing as 3 instead of 4 as there are only 3.
How can I reset the tab index in the program, or else any solution where I can read the correct index of tab as it was before removing it?
This is where i am adding the new tab and the close event.
HorizontalPanel horizontalPanel = new HorizontalPanel();
Image image = new Image();
Label label = new Label("New Report: " + k);
label.setWordWrap(false);
horizontalPanel.add(label);
horizontalPanel.add(image);
image.setUrl("images/1305803163_close.png");
tabpanel.add(newTab[k], horizontalPanel);
tabindexx[k] = k;
image.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
tabpanel.remove(tabpanel.getTabBar().getSelectedTab());
}
});
and in some part of the code I am accessing the tab index like this
int selectedtab = tabpanel.getTabBar().getSelectedTab();
Of course this will return an index based on the number of tabs present at that particular moment, so I need to store them somewhere or else I have to reset the tab index after I close.
That will happen because the index number is the index for the current set of tabs. (if one closes, it obviously impacts the others).
I am a little rusty with GWT now, but i believe the only way to remove or select tabs is using index.
One solution could be to manage a List of tab representatives (some tab identifier) in your code, and do a mirror remove in that list when a delete occurs in your code. Then you can lookup the new index of the tab that you want to update after the delete and get the right index. (Tab identifier can be as simple as the original index of the tab when you started before any deletes)