Fitting a big grid (wxGrid) in a dialog (wxDialog) - c++

Here is my layout:
I have a sizer that contains a grid (with a proportion of 1) and a ok/cancel button bar
The all thing is in a wxDialog
Here it is:
|||||||||||||||
| |
| GRID |
| |
| |
| |
|||||||||||||||
| OK CANCEL |
|||||||||||||||
The issue is that the grid contains too many row, and over flow the screen, so in the end I don't see the top part of the dialog. Is there a way, when calling Fit() on the dialog, to limit its height ?
I have tried stuff like this: SetSizeHints(-1,-1,-1,500); and SetMaxSize(500,500) but it did not worked.
Also I have tried to do that: this->SetSize(this->GetSize().GetX(), 500);, but since the vertical scroll bar appears on the grid, it is not wide enough and a horizontal scroll bar shows up.
EDIT
In the constructor I call wxGrid(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)

The easiest way to handle this is to use a grid of fixed size. If there are more rows than will fit, then a scroll bar will appear. You set the size you want in the constructor.
new wxGrid( this, IDC_grid, wxPoint(-1,-1),wxSize(igridxsize,igridysize));
If you want the size of the grid to adjust, e.g. when the user resizes the application window, things are a bit more complex. You need handle the window size event and change the grid size as appropriate.
Something along these lines:
myDialog::OnSize(wxSizeEvent& event);
{
wxSize dialogSize = event.GetSize();
myGrid->OnSize( wxSizeEvent(
dialogSize.GetWidth() * 0.9, dialogSize.GetHeight() * 0.7 ));
}

Related

Re-dock two QToolbars back in the same QToolbarArea

I'm working on a Qt project, where I need to get the toolbar positions at run-time. I used QMainWindow::toolBarArea(QToolBar *toolbar) to get the current docked area of the toolbar. And then I can use that later with QMainWindow::addToolBar ( Qt::ToolBarArea area, QToolBar * toolbar ).
Let's assume I dock two toolbars in a single area (i.e. Bottom area), as below.
-----------------------------------
| Toolbar 1 |
-----------------------------------
| Toolbar 2 |
-----------------------------------
Then I save the area obtained from QMainWindow::toolBarArea, using QSettings and then load them back with QMainWindow::addToolBar , it loads as below.
-----------------------------------
| Toolbar 1 | Toolbar 2 |
-----------------------------------
Is there any way to re-dock them the original form, without using QMainWindow::saveState()?

Simple way to get the current docked area of a QToolbar

I'm working on a Qt project, where I need to get the toolbar positions at run-time. Is there any way to get the current positioning of a QToolbar inside a QMainWindow ?
Thanks.
EDIT:
Thanks for the answer and I got 75% working. But there is a problem in QMainWindow::toolBarArea(QToolBar * toolbar).
When I dock two toolbars in a single area (i.e. Bottom area), as below.
-----------------------------------
| Toolbar 1 |
-----------------------------------
| Toolbar 2 |
-----------------------------------
Then I save the area obtained from QMainWindow::toolBarArea, using QSettings and then load them back, it loads as below.
-----------------------------------
| Toolbar 1 | Toolbar 2 |
-----------------------------------
Is there any way to stop that as well?
Within the scope of QMainWindow, you can call QMainWindow::toolBarArea(QToolBar *toolbar) to get the toolbar position.
Returns the Qt::ToolBarArea for toolbar. If toolbar has not been added
to the main window, this function returns Qt::NoToolBarArea.
It returns the enum:
enum ToolBarArea {
LeftToolBarArea = 0x1,
RightToolBarArea = 0x2,
TopToolBarArea = 0x4,
BottomToolBarArea = 0x8,
ToolBarArea_Mask = 0xf,
AllToolBarAreas = ToolBarArea_Mask,
NoToolBarArea = 0
};

win32 List View Abbreviating Text

I'm using win32 to create a list view with downloaded icons, however, the text is abbreviated at approximately 19 characters (as about size 12 font, Segoe UI). I have included the CreateWindow and item creation code I'm using for it.
Any advice would be appreciated.
HWND airlinelist = CreateWindow(WC_LISTVIEW,L"",WS_CHILD | LVS_LIST | WS_TABSTOP | WS_BORDER,18,104,323,74,hwnd,(HMENU)3,hinst,NULL);
LVITEM newi;
ZeroMemory(&newi,sizeof(LVITEM));
const wchar_t* n = L"Client Website Name, website.com"
newi.pszText = newc;
newi.mask = LVIF_TEXT | LVIF_IMAGE;
newi.iImage = 0;
ListView_InsertItem(airlinelist,&newi);
The above would create a list view with the icon and something to the effect of "Client Website Nam..." despite it only taking up half of the list view's width.
I'll assume you're using LVS_LIST mode because the style is shown in your code sample. You can use the LVM_SETCOLUMNWIDTH message to adjust the column size once you've added items to the list control. You can also use the ListView_SetColumnWidth macro. E.g.:
SendMessage(airlinelist, LVM_SETCOLUMNWIDTH, 0, 300);
This would set the columns to 300 pixels wide. If you're actually using LVS_REPORT mode you would need to set the width for each column individually.

Qt QVBoxLayout: How to divide the layout in fixed height Boxes?

I want to divide my window in the following manner
Build a vertical layout
-------------------------
| |
-------------------------
| |
| |
| |
| |
| |
| |
-------------------------
using QVBoxLayout. I want to maintain this ratio at all times. I will disabling re-sizing the window. Right now I have the following code.
QVBoxLayout baseLayout = new QVBoxLayout(this);
QLabel *widget = new QLabel(NULL);
widget->setStyleSheet("background-color: rgb(0, 39, 118)");
widget->setGeometry(0,0,400, 30);
widget->setPixmap(QPixmap("Logo-Large.gif"));
baseLayout->addWidget(widget);
...
This divides the window in equal parts. I can't use the form designer as I am building this UI dynamically.
Is there any property on QVBoxLayout that I can use to achieve this? Or Using this QVBoxLayout is simply wrong, if so please suggest an alternative.
Thanks and Regards,
Atul.
To make a QVBoxLayout keep a fixed ratio between two elememts, give them stretch parameters in addWidget. A stretch parameter of N that is x times another stretch parameter Y will make the corresponding widget have a height x times higher than the other widget.

Understanding wxWidgets sizers

I'm still getting used to the sizers in wxWidgets, and as such can't seem to make them do what I want.
I want a large panel that will contain a list of other panels/boxes, which each then contain a set of text fields
----------------------
| label text box |
| label2 text box2 |
----------------------
----------------------
| label text box |
| label2 text box2 |
----------------------
----------------------
| label text box |
| label2 text box2 |
----------------------
I also need to be able to add (at the end), and remove(anywhere) these boxes.
If there's too many to fit in the containing panel a vertical scroll bar is also required.
This is what I've tried so far, it works for the first box that's created with the containing panel, but additional added items are just a small box in the top left of the main panel, even though the sizer code is the same for all boxes.
//itemsList is a container containg a list of *Item pointers to each box/panel/whatever the right name is
Items::Items(wxWindow *parent)
:wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
{
//one sstarting item
OnAdd(wxCommandEvent());
}
void Items::OnAdd(wxCommandEvent &event)
{
unsigned id = itemsList .size();
Item *item = new Item(this,id);
itemsList .push_back(item);
RebuildSizer();
}
void Items::RebuildSizer()
{
this->SetSizer(0,true);
wxBoxSizer *sizerV = new wxBoxSizer(wxVERTICAL);
for(std::vector<Item*>::iterator it = itemsList .begin(); it != itemsList .end(); ++it)
sizerV->Add(*it, 1, wxEXPAND | wxLEFT | wxRIGHT, 5);
SetSizer(sizerV);
}
void Items::OnRemove (wxCommandEvent &event, unsigned itemId)
{
delete itemsList [itemId];
itemsList .erase(items.begin()+itemId);
for(std::vector<Item*>::iterator it = itemsList .begin()+itemId; it != itemsList .end(); ++it)
(*it)->ChangeId(itemId++);
RebuildSizer();
}
Also what's the best way to lay out the contents of each box? I was thinking of using a 2 by 2 grid sizer but I'm not sure how to make the text boxes to expand to be as wide as possible while making the labels stay as small as possible (but also maintaining the alignment between the 2 text boxes)?
"If theres too many to fit in the containing panel a vertical scroll bar is also required."
You could have a look at wxScrolledWindow.
"additional added items are just a small box in the top left of the main panel"
I am not sure, but, maybe a call to wxSizer::Layout() will help.
"Also whats the best way to lay out the contents of each box?"
Have a look at this sizerdemo. If it is not mandatory, that the labels stay as small as possible, you could give the labels a fixed width and only let the text boxes grow. If you want to adapt the size when adding or removing new boxes, you could implement the OnSize() event handler.
May I suggest to you to post this question to one of the wxWidgets mailing list? They will be able to help you very quickly.
Can I also recommend the wxForum, I have found it very useful for wxWidgets questions in the past.
More specifically for scrolling wxScrolledWindow should help, use wxScrolledWindow->SetSizer with your top level sizer (the one that contains your controls) to set up a scrolled area, also check out the samples called scroll, scrollsub and vscroll included in wxWidgets (in the samples directory of your wxwidgets install).