Buttons side-by-side using labltk - ocaml

I am using labltk in Ocaml. I would like to create three buttons side-by-side.
Suppose the following code :
#load "labltk.cma";;
let top = openTk() in
...
let button1 = Button.create
~text:"Button 1"
~command:(fun () -> Tk.closeTk (); exit 0)
top in
let button2 = Button.create
~text:"Button 2"
~command:(fun () -> Tk.closeTk (); exit 0)
top in
let button3 = Button.create
~text:"Button 3"
~command:(fun () -> Tk.closeTk (); exit 0)
top in
...
Right now, the buttons are one over the others. Is there a workaround the make the button side-by-side

For a simplistic layout You may just pack them:
pack ~side:`Left [button1;button2;button3] ;;

Related

How do I toggle between UIWindows?

Scenario:
I've created an overlay window (with tag = 100) that I eventually want to dismiss. But the following code doesn't work:
UIApplication.shared.windows.first?.becomeKey()
UIApplication.shared.windows.last?.resignKey()
(lldb) po UIApplication.shared.windows
▿ 2 elements
- 0 : <UIWindow: 0x7fa698d0ad00; frame = (0 0; 768 1024); gestureRecognizers = <NSArray: 0x600000048550>; layer = <UIWindowLayer: 0x6000000278a0>>
- 1 : <UIWindow: 0x7fa698d14bb0; frame = (0 0; 768 1024); autoresize = W+H; tag = 100; gestureRecognizers = <NSArray: 0x600000252a50>; layer = <UIWindowLayer: 0x600000229660>>
Any ideas to either toggle or delete the overlay window?
Simply set the window's isHidden property to true:
var overlayWindow: UIWindow?
...
overlayWindow?.isHidden = true
overlayWindow = nil // optional
If you set any references to this window to nil, the window will be disposed.
Please also note that you are not supposed to call resignKey(). From its documentation (emphasis mine):
Discussion
Never call this method directly. The system calls this
method and posts UIWindowDidResignKey to let the window know when it
is no longer key. The default implementation of this method does
nothing, but subclasses can override it and use it to perform tasks
related to resigning the key window status.
The same is true for becomeKey(), by the way. You probably want to use makeKey() or makeKeyAndVisible().
This is essentially a two-part question.
How do I display a created UIWindow and
How do I dismiss it?
I learned that I have to keep a reference to the newly-created UIWindow rather than merely have local-scope reference. ...which is obvious.
Once I have a persistent reference to the ancillary UIWindow, I can merely assign nil to it to remove it:
var hamburgerWindow:UIWindow?
#IBAction func displayOverlayWindowAction() {
guard hamburgerWindow != nil else {
displayOverLay()
return
}
hamburgerWindow = nil
}

Create a function that selects a Main Menu bar based on the selected tab

I am fairly new to c++ and am wondering if there is a way to create a function that will select a menu bar created in the MFC Menu Editor and display it at the top of the window.
The idea is to have a different menu bar for each of the tabs because each tab will have different options.
For example a menu bar called ID_REGMENUBAR for Doom Reg and ID_SCRIPTMENUBAR for the Script
If more info is needed please say so. Thanks!
Use CMenu::LoadMenu and CWnd::SetMenu. For example, declare member data:
CMenu m_menu1, m_menu2;
Initialize the menu once:
m_menu1.LoadMenu(ID_REGMENUBAR);
m_menu2.LoadMenu(ID_SCRIPTMENUBAR);
Use SetMenu(&m_menu1) to assign the menu on run time. You can respond to tab selection changes by looking TCN_SELCHANGE
BEGIN_MESSAGE_MAP(...)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnTabSelection)
END_MESSAGE_MAP()
void CMyWnd::OnTabSelection(NMHDR*, LRESULT*)
{
int tab = m_Tab.GetCurSel();
CMenu *pMenu = NULL;
if (tab == 0) pMenu = &m_menu1;
if (tab == 1) pMenu = &m_menu2;
CFrameWnd* frame = (CFrameWnd*)AfxGetMainWnd();
frame->SetMenu(pMenu);
}

How can I get a VC++ Form app to detect a radio button selection?

So I'm a novice with C++ Forms. I'm in VC++2010 Express. I decided to start learning how to make form apps and not just console apps. So I wanted to make one of my console apps into a form app.
So I have this code here:
PlaySound("Millionaire/£100Play.wav",NULL,SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
question -> Text = "Let's Play!";
question -> Text = "question";
A -> Text = "Answer A";
B -> Text = "Answer B";
C -> Text = "Answer C";
D -> Text = "Answer D";
if (BN_CLICKED && AButton->Checked ) //This is me testing it out, more likely than not wrong
{
PlaySound("C:/Users/user/Downloads/Millionaire/£100correct.wav",NULL,SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
A -> BackColor = System::Drawing::Color::Green;
questionsAway -> Text = "Away: 14";
moneyWon -> Text = "£100";
indicator -> BackColor = System::Drawing::Color::Green;
moneyWorth -> Text = "£200";
moneyLost -> Text = "£100";
info -> Text = "Enter text relating the answer to the question or general facts.";
}
else
{
PlaySound("C:/Users/user/Downloads/Millionaire/£100and£64000lose.wav",NULL,SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
indicator -> BackColor = System::Drawing::Color::Red;
}
}
So what this does is display some text in text boxes along with some sounds. Now the main problem here is the if and else statements. I have radio buttons for the user to select, each one corresponding to answer A, B, C or D. Now what happens here is instead of the program waiting for input, it immediately goes right to the else statement on startup as A isn't selected and treats the answer as incorrect. My question is, how can I get the program to wait for input OR detect when an button is selected?

Qt dynamic properties not set when in if statement

I'm facing a strange issue in my Qt application... I have a Widget inheriting QLabel with the following stylesheet:
QLabel { padding: 10px ; }
QLabel[current-player=true] { background: blue ; }
QLabel:disabled { background: #eee ; }
And a method:
void MyWidget::updateInformation () {
this->setEnabled (m_player->isEnable ());
if (m_player->isCurrentPlayer ()) {
qDebug () << "Setting current player to true: " << PlayerInfo::toString (m_player->player ()) ;
this->setProperty ("current-player", true);
}
// this->setProperty ("current-player", true);
qDebug () << "Property current player: " << this->property ("current-player") ;
}
As you can see, I want to set the background of my widget to blue when the current-player property is true, so I have the conditions m_player->isCurrentPlayer().
I have a line commented, which was used to test if the property worked, and it did. When I uncomment the line, the background becomes blue.
What is strange is that my debug output is (when the line is commented):
Setting current player to true: "Player1"
Property current player: QVariant(bool, true)
Setting current player to true: "Player1"
Property current player: QVariant(bool, true)
As you can see, the execution goes inside the if statement because I see the Setting current player... output, and the current-player property is true, but the background stay white...
I don't understand my the code works when I set the property all the time and doesn't work if I set the property in a if statement which is taken.
If anyone as an idea, it'll help me a lot!
Thanks!
It's OK. Stylesheets are not recomputed when you change custom properties. Because of performance issues.
Solution: Call polish() and unpolish() to a widget with stylesheet.
P.S. I want to note, that usage of custom properties for such style customization is bad practice, because in case of complex styles it will cause UI lags.

How to edit the text in the QListWidget on the run time by single clicking them?

class genericTaskList : public QListWidget
{
Q_OBJECT
public:
unsigned int rowCounter;
genericTaskList (QWidget *parentWidget)
{
setParent (parentWidget);
setFixedSize (445, 445);
QListWidgetItem *defaultText = new QListWidgetItem ("Double click here to compose the new task.");
defaultText->setFlags (defaultText->flags () | Qt :: ItemIsEditable);
rowCounter = 0;
insertItem (rowCounter, defaultText);
QObject :: connect (this, SIGNAL (itemDoubleClicked (QListWidgetItem*)), this, SLOT (addDefaultText (QListWidgetItem*)));
QObject :: connect (this, SIGNAL (itemChanged (QListWidgetItem*)), this, SLOT (addDefaultText (QListWidgetItem*)));
}
public slots:
void addDefaultText (QListWidgetItem*f)
{
// Returns the current row number.
unsigned int currentRow = row (f);
// Returns the current row text.
QString textOfCurrentRow = f->text ();
// The new default row should get inserted if and only if, the last row created has been double clicked and its default text has been changed.
if ((currentRow == rowCounter)
&& (textOfCurrentRow.toStdString () != "Double click here to compose the new task.")
&& (textOfCurrentRow.toStdString () != ""))
{
++rowCounter;
QListWidgetItem *defaultText = new QListWidgetItem ("Double click here to compose the new task.");
defaultText->setFlags (defaultText->flags () | Qt :: ItemIsEditable);
insertItem (rowCounter, defaultText);
setCurrentRow (rowCounter);
}
else if (textOfCurrentRow.toStdString () == "")
{
takeItem (rowCounter);
QListWidgetItem *defaultText = new QListWidgetItem ("Double click here to compose the new task.");
defaultText->setFlags (defaultText->flags () | Qt :: ItemIsEditable);
insertItem (rowCounter, defaultText);
setCurrentRow (rowCounter);
}
}
};
The problem here is that I can edit the text if and only if I double click the text. Single click or anything else doesn't work. I tried changing that signal from double click to single click, didn't help.
Please guide - Double clicking all the time is a pain.
You can use QAbstractItemView::CurrentChanged as the edit trigger for your list widget. This means that if you click an item it will be editable. This is the case not only for clicking on it, but also for switching among the items with the arrow keys for example. Unfortunately there is no flag for "edit on single click" or something like that...
setEditTriggers( QAbstractItemView::CurrentChanged );
Overview of all triggers