当前位置:网站首页>QT direction key to move focus
QT direction key to move focus
2022-06-13 04:55:00 【qq_ thirty-nine million two hundred and eighty thousand seven h】
problem
qt Use at The built-in direction key , Moving focus is limited , In some cases , The arrow keys move the position of some parts . For example, this one qt in example, By moving the focus up and down , You cannot move the right column from the left column . Unless used tab key .
How to solve :
Scheme 1 :
Give each control an index , Index by operation ( Addition and subtraction ), Determine the position of the current part . But when the control changes , For example, a part is hidden , Judgment operation is required . Different interface changes , It's hard to adapt to .
Option two :
Give each control an index , Index by operation ( Addition and subtraction ), Determine the position of the current part , meanwhile Operate controls on an interface , Create a linked list , Linked list members have focus control pointers , The focus controls are sequentially indexed to form , The focus control pointer corresponds to the focus control sequence index one by one .
How does that change with the interface , Through the interface control visible attribute , Control is hidden , Skip the control directly , Look up the next one in the linked list .
Example ( Option two ):
Header file definition :
struct MovableWidget
{
MovableWidget(QWidget * widget,int pos_index)
{
widget_ = widget;
pos_index_ = pos_index_;
}
QWidget * widget_;
int pos_index_;
};
QList<MovableWidget> movable_widget_list;
int pos;keyPressEvent rewrite
void Widget::keyPressEvent(QKeyEvent *e)
{
qDebug() << "keyPressEvent" << e <<e->key()<< Qt::Key_A << endl;
if(e->key() == Qt::Key_A) //right
{
int temp_pos = pos ;
int size = movable_widget_list.size();
for(int i =0; i < size;i++ )
{
pos = pos + 1;
pos = pos % size;
if(pos == temp_pos)
{
break;
}
else if(movable_widget_list.at(pos).widget_ == NULL)
{
continue;
}
else if(movable_widget_list.at(pos).widget_->isVisible())
{
qDebug() << "pos:" << pos;
movable_widget_list.at(pos).widget_->setFocus();
break;
}
else
{
continue;
}
}
}
//keyPressEvent(e);
}The constructor in the interface part adds the sub part to the linked list .
movable_widget_list.append(MovableWidget(ui->toolButton,1));
movable_widget_list.append(MovableWidget(ui->toolButton_2,2));
movable_widget_list.append(MovableWidget(ui->toolButton_3,3));
movable_widget_list.append(MovableWidget(ui->toolButton_4,4));
movable_widget_list.append(MovableWidget(ui->toolButton_5,5));
movable_widget_list.append(MovableWidget(ui->toolButton_6,6));
movable_widget_list.append(MovableWidget(ui->toolButton_7,7));
movable_widget_list.append(MovableWidget(ui->toolButton_8,8));
movable_widget_list.append(MovableWidget(ui->toolButton_9,9));effect :

边栏推荐
- PowerShell plus domain add computer module
- Robot pose description and coordinate transformation
- Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
- Third party comment plugin
- 2022年氧化工艺操作证考试题库及模拟考试
- PowerDesigner easy to use
- Analysis on the usage, response and global delivery of provide/inject
- Force buckle 92 Reverse linked list II
- Configuration used by automatic teaching evaluation script
- The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
猜你喜欢

Several methods of identifying equivalent circuit of circuit drawing

The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes

Solution to sudden font change in word document editing

CMB written test graphical reasoning

Section 5 - Operator details

Interpretation of QT keypressevent

CMB's written test -- data analysis

Leetcode game 297 (20220612)

Shell built-in string substitution

【JS解决】leedcode 200. 岛屿数量
随机推荐
小C的记事本
Conception d'un système basé sur MVC avec javaswing JDBC
Leetcode game 297 (20220612)
利用Javeswingjdbc基於mvc設計系統
Reductive elimination
Sampo Lock
QT interface rendering style
Autumn wind, dust, youth
Analysis of the principle of V-model and its application in user defined components
2022 oxidation process operation certificate examination question bank and simulation examination
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Flutter dart variables and constants
How to lay copper in AD (aluminum designer)
[leetcode]- binary search
LeetCode第297场周赛(20220612)
Section 8 - Practical commissioning techniques
第三方评论插件
Vercel uses HTTP caching
C language exercise 1
ES6 learning