久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使 QPushButton 可按下輸入鍵?

How to make a QPushButton pressable for enter key?(如何使 QPushButton 可按下輸入鍵?)
本文介紹了如何使 QPushButton 可按下輸入鍵?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想讓我的應用程序筆記本電腦友好.我可以選擇任何地方,但如果我選擇一個 說明了這些:><塊引用>

默認和自動默認按鈕決定當用戶在對話框中按 Enter.

此屬性設置為 true 的按鈕(即對話框的默認值按鈕,) 將在用戶按下 Enter 時自動按下,有一個例外:如果 autoDefault 按鈕當前具有焦點,則按下自動默認按鈕.當對話框有 autoDefault 按鈕時但沒有默認按鈕,按回車將按當前具有焦點的 autoDefault 按鈕,或者如果沒有按鈕焦點,焦點鏈中的下一個自動默認按鈕.

在對話框中,一次只能有一個按鈕作為默認按鈕.該按鈕隨后會顯示一個額外的框架(取決于GUI 風格).

默認按鈕行為僅在對話框中提供.按鈕可以始終通過按空格鍵從鍵盤單擊按鈕有焦點.

如果當前默認按鈕的默認屬性設置為false當對話框可見時,新的默認值將自動為下次對話框中的按鈕獲得焦點時分配.

還值得查看 QDialog 和 QMessageBox.

I want to make my app laptop friendly. I can tab to everywhere, but if I tab to a QPushButton I can't press it with Enter, only with space.
What's the problem? How to make it pressable for Enter?

解決方案

tl;dr

  1. In the Qt Creator's UI view, select the button you want to make pressable for Enter.
  2. In the right side at the Property Editor scroll down to the blue part titled QPushButton.
  3. Check the checkbox by autoDefault or default.

Most of the cases the main different between autoDefault and default is how the button will be rendered. But there are cases where it can cause unexpected things so for more information read more below.


Full review

Overview

Every QPushButton has 3 properties that are not inherited. From these, two (default and autoDefault) have a major role when we place buttons on QDialogs, because these settings (and the focus on one of the buttons) decides which button will be pressed if we hit Enter.
All of these properties are set false by default. Only expection is autoDefault that will be true if the button has a QDialog parent.

Every time you press space the button with the focus on it will be pressed. The followings will describe what happens if you press Enter.

Default property

If this is set true, the button will be a default button.
If Enter is pressed on the dialog, than this button will be pressed, except when the focus is on an autoDefault button.

There should be only one default button. If you add more then the last one added will be the default button.

AutoDefault property

If this is set true, the button will be an autoDefault button.
If Enter is pressed on the dialog, than this button will be pressed if the focus is on it.

If the focus is not on an autoDefault button and there is no default button than the next autoDefault button will be pressed for Enter.

Flat property

If this is set true, then the border of the button will not be raised.

Example tables

The following tables show which button will be pressed with different buttons on different focus. The buttons are added from left to right.

Test code

The following code is a way to add buttons to a dialog. It can be used for testing by changing the boolean values at setDefault() and/or setAutoDefault().
You just need to create a window, add a QPushButton called pushButton and a QLabel called label (that is the default naming). Don't forget to #include <QMessageBox>. Then copy this code to the button's clicked() signal:

void MainWindow::on_pushButton_clicked()
{
   QMessageBox msgBox;

   QPushButton button("Button");
   button.setDefault(false);
   button.setAutoDefault(false);
   msgBox.addButton(&button, QMessageBox::ActionRole);

   QPushButton autodefaultbutton("AutoDefault Button");
   autodefaultbutton.setDefault(false);
   autodefaultbutton.setAutoDefault(true);
   msgBox.addButton(&autodefaultbutton, QMessageBox::ActionRole);

   QPushButton autodefaultbutton2("AutoDefault Button2");
   autodefaultbutton2.setDefault(false);
   autodefaultbutton2.setAutoDefault(true);
   msgBox.addButton(&autodefaultbutton2, QMessageBox::ActionRole);

   QPushButton defaultbutton("Default Button");
   defaultbutton.setDefault(true);
   defaultbutton.setAutoDefault(false);
   msgBox.addButton(&defaultbutton, QMessageBox::ActionRole);

   msgBox.exec();

   if (msgBox.clickedButton() == &button) {
      ui->label->setText("Button");
   } else if (msgBox.clickedButton() == &defaultbutton) {
      ui->label->setText("Default Button");
   } else if (msgBox.clickedButton() == &autodefaultbutton) {
      ui->label->setText("AutoDefault Button");
   } else if (msgBox.clickedButton() == &autodefaultbutton2) {
      ui->label->setText("AutoDefault Button2");
   }
}

Display

If you compile the code you can get this window. You doesn't even have to click to the buttons because the way they are rendered by the OS shows which one will be pressed if you hit Enter or space.

Official documentation

Most of this answer was made according to the official documentation.
The QPushButton documentation made by Qt states these:

Default and autodefault buttons decide what happens when the user presses enter in a dialog.

A button with this property set to true (i.e., the dialog's default button,) will automatically be pressed when the user presses enter, with one exception: if an autoDefault button currently has focus, the autoDefault button is pressed. When the dialog has autoDefault buttons but no default button, pressing enter will press either the autoDefault button that currently has focus, or if no button has focus, the next autoDefault button in the focus chain.

In a dialog, only one push button at a time can be the default button. This button is then displayed with an additional frame (depending on the GUI style).

The default button behavior is provided only in dialogs. Buttons can always be clicked from the keyboard by pressing Spacebar when the button has focus.

If the default property is set to false on the current default button while the dialog is visible, a new default will automatically be assigned the next time a pushbutton in the dialog receives focus.

It's also worth to check QDialog and QMessageBox.

這篇關于如何使 QPushButton 可按下輸入鍵?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 99精品欧美一区二区蜜桃免费 | 国产欧美精品一区二区三区 | 中文字幕观看 | 自拍偷拍中文字幕 | 成人国产精品色哟哟 | 99日韩| 欧美精品99 | 免费久久网 | 成人在线精品视频 | 国产999精品久久久久久绿帽 | 天天草天天 | 一区二区久久电影 | 精品一区二区三区在线观看国产 | 青青草av在线播放 | 永久精品 | 在线播放中文 | 国产精品一区二区视频 | 国产精品一区二区在线免费观看 | 亚洲综合视频 | 亚洲精选一区二区 | 成人精品视频99在线观看免费 | 国产高清在线精品 | 亚洲国产成人av好男人在线观看 | 亚洲国产精品久久久 | 精品久久久久久久久久久久久久 | 欧美一级毛片在线播放 | 超碰伊人| 人人艹人人 | 欧美综合在线视频 | 欧美一区二区三区视频在线观看 | 一区二区三区四区国产 | 精品国产欧美一区二区三区成人 | 免费99精品国产自在在线 | 美女国产精品 | 国产精品美女一区二区三区 | 精品久久久久久中文字幕 | 国产精品免费视频一区 | 免费在线观看成人 | 久久国产精品久久久久久 | 97av视频| 四虎影院在线观看免费视频 |